home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / Ang261Lib.lha / src / dungeon.c < prev    next >
C/C++ Source or Header  |  1994-10-22  |  93KB  |  3,501 lines

  1. /*
  2.  * dungeon.c: the main command interpreter, updating player status 
  3.  *
  4.  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke 
  5.  *
  6.  * This software may be copied and distributed for educational, research, and
  7.  * not for profit purposes provided that this copyright and statement are
  8.  * included in all such copies. 
  9.  */
  10.  
  11. #include "constant.h"
  12. #include "config.h"
  13. #include "types.h"
  14. #include "externs.h"
  15. #include "monster.h"
  16.  
  17. #ifdef USG
  18. #ifndef ATARIST_MWC
  19. #include <string.h>
  20. #endif
  21. #else
  22. #include <strings.h>
  23. #endif
  24.  
  25. /* Lets do all prototypes correctly.... -CWS */
  26. #ifndef NO_LINT_ARGS
  27. #ifdef __STDC__
  28. static void        regenhp(int);
  29. static void        regenmana(int);
  30. static const char *value_check(inven_type *);
  31. #else
  32. static void        regenhp();
  33. static void        regenmana();
  34. /* static int      enchanted(); */
  35. static const char *value_check();
  36. #endif
  37.  
  38. static void print_feeling();
  39. static char original_commands();
  40. static void do_command();
  41. static int  valid_countcommand();
  42. static void examine_book();
  43. static void activate();
  44. static void go_up();
  45. static void go_down();
  46. static void jamdoor();
  47. static void refill_lamp();
  48. static void regen_monsters();
  49. #endif
  50.  
  51. /* ANGBAND game module                    -RAK-     */
  52. /* The code in this section has gone through many revisions, and */
  53. /* some of it could stand some more hard work.    -RAK-           */
  54.  
  55. /* It has had a bit more hard work.            -CJS- */
  56.  
  57. int good_item_flag = FALSE;
  58. int create_up_stair = FALSE;
  59. int create_down_stair = FALSE;
  60.  
  61. void 
  62. dungeon()
  63. {
  64.     int                    find_count, i;
  65.     int                    regen_amount; /* Regenerate hp and mana */
  66.     char                   command;      /* Last command           */
  67.     register struct misc  *p_ptr;
  68.     register inven_type   *i_ptr;
  69.     register struct flags *f_ptr;
  70.  
  71. /* Main procedure for dungeon.            -RAK-     */
  72. /* Note: There is a lot of preliminary magic going on here at first */
  73.  
  74. /* init pointers. */
  75.     f_ptr = &py.flags;
  76.     p_ptr = &py.misc;
  77.  
  78.     i_ptr = &inventory[INVEN_LIGHT];
  79.  
  80. /* Check light status for setup       */
  81.     if (i_ptr->p1 > 0 || f_ptr->light)
  82.     player_light = TRUE;
  83.     else
  84.     player_light = FALSE;
  85.     if (i_ptr->tval == TV_LIGHT)
  86.     i = i_ptr->subval;
  87.     else
  88.     i = 195;
  89.     light_rad = 1 + (i < 190) + (i == 4 || i == 6);
  90.  
  91. /* Check for a maximum level           */
  92. /* Added check to avoid -50' being "deepest", since max_dlv unsigned -CFT */
  93.     if ((dun_level >= 0) && ((unsigned) dun_level > p_ptr->max_dlv))
  94.     p_ptr->max_dlv = dun_level;
  95.  
  96. /* Reset flags and initialize variables  */
  97.     command_count  = 0;
  98.     eof_flag       = FALSE;
  99.     find_count     = 0;
  100.     new_level_flag = FALSE;
  101.     find_flag      = FALSE;
  102.     teleport_flag  = FALSE;
  103.     mon_tot_mult   = 0;
  104.     old_rad        = (-1);
  105.     coin_type      = 0;
  106.     opening_chest  = FALSE;
  107.  
  108. #ifdef TARGET
  109.     target_mode = FALSE; /* target code taken from Morgul -CFT */
  110. #endif
  111.     cave[char_row][char_col].cptr = 1;
  112.  
  113.     if (create_up_stair && (dun_level == 0))    /* just in case... */
  114.     create_up_stair = FALSE;
  115.     if (create_up_stair || create_down_stair) {
  116.     register cave_type *c_ptr;
  117.     register int        cur_pos;
  118.  
  119.     c_ptr = &cave[char_row][char_col];
  120.     if ((c_ptr->tptr == 0) ||
  121.         ((t_list[c_ptr->tptr].tval != TV_STORE_DOOR) && /* if not store */
  122.          ((t_list[c_ptr->tptr].tval < TV_MIN_WEAR) ||   /* if no artifact here -CFT */
  123.           (t_list[c_ptr->tptr].tval > TV_MIN_WEAR) ||
  124.           !(t_list[c_ptr->tptr].flags2 & TR_ARTIFACT)))) {
  125.         if (c_ptr->tptr != 0)
  126.         (void)delete_object(char_row, char_col);
  127.         cur_pos = popt();
  128.         c_ptr->tptr = cur_pos;
  129.         if (create_up_stair)
  130.         invcopy(&t_list[cur_pos], OBJ_UP_STAIR);
  131.         else if (create_down_stair && !is_quest(dun_level))
  132.         invcopy(&t_list[cur_pos], OBJ_DOWN_STAIR);
  133.     } else
  134.         msg_print("The object resists your attempt to transform it into a stairway.");
  135.     create_down_stair = FALSE;
  136.     create_up_stair = FALSE;
  137.     }
  138. /* Ensure we display the panel. Used to do this with a global var. -CJS- */
  139.     panel_row = panel_col = (-1);
  140. /* Light up the area around character       */
  141.     check_view();
  142.  
  143. /* must do this after panel_row/col set to -1, because search_off() will call
  144.  * check_view(), and so the panel_* variables must be valid before
  145.  * search_off() is called 
  146.  */
  147.     if (py.flags.status & PY_SEARCH)
  148.     search_off();
  149. /* Light,  but do not move critters        */
  150.     creatures(FALSE);
  151. /* Print the depth               */
  152.     prt_depth();
  153.  
  154. /* FIXME: figure this out */
  155.     if (((turn - old_turn) > randint(50) + 50) && dun_level) {
  156.     unfelt = FALSE;
  157.     print_feeling();
  158.     }
  159.     old_turn = turn;
  160.  
  161. /* Loop until dead,  or new level         */
  162.     do {
  163.     /* Increment turn counter             */
  164.     turn++;
  165. #ifdef CHECKHOURS
  166. #ifndef MAC
  167.     /* The Mac ignores the game hours file         */
  168.     /* Check for game hours                   */
  169.     if (((turn % 100) == 1) && !check_time())
  170.         if (closing_flag > 2) {
  171.         msg_print("The gates to ANGBAND are now closed.");
  172.         (void)strcpy(died_from, "(closing gate: saved)");
  173.         if (!save_char()) {
  174.             (void)strcpy(died_from, "a slammed gate");
  175.             death = TRUE;
  176.         }
  177.         exit_game();
  178.         } else {
  179.         disturb(0, 0);
  180.         closing_flag++;
  181.         msg_print("The gates to ANGBAND are closing due to high load.");
  182.         msg_print("Please finish up or save your game.");
  183.         }
  184. #endif
  185. #endif                   /* CHECKHOURS */
  186.  
  187.     /* turn over the store contents every, say, 1000 turns */
  188.     if ((dun_level != 0) && ((turn % 1000) == 0)) {
  189.     /* if (peek) msg_print("Store update: "); */
  190.         store_maint();
  191.     /* if (peek) msg_print("Complete "); */
  192.     }
  193.     /* Check for creature generation         */
  194.     if (randint(MAX_MALLOC_CHANCE) == 1)
  195.         alloc_monster(1, MAX_SIGHT, FALSE);
  196.     if (!(turn % 20))
  197.         regen_monsters();
  198.     /* Check light status                   */
  199.     i_ptr = &inventory[INVEN_LIGHT];
  200.     if (player_light)
  201.         if (i_ptr->p1 > 0) {
  202.         if (!(i_ptr->flags2 & TR_LIGHT))
  203.             i_ptr->p1--;   /* don't dec if perm light -CFT */
  204.         if (i_ptr->p1 == 0) {
  205.             player_light = FALSE;
  206.             disturb(0, 1);
  207.         /* unlight creatures */
  208.             creatures(FALSE);
  209.             msg_print("Your light has gone out!");
  210.         } else if ((i_ptr->p1 < 40) && (randint(5) == 1) &&
  211.                (py.flags.blind < 1) &&
  212.                !(i_ptr->flags2 & TR_LIGHT)) { /* perm light doesn't dim -CFT */
  213.             disturb(0, 0);
  214.             msg_print("Your light is growing faint.");
  215.         }
  216.         } else {
  217.         if (!f_ptr->light) {
  218.             player_light = FALSE;
  219.             disturb(0, 1);
  220.         /* unlight creatures */
  221.             creatures(FALSE);
  222.         }
  223.         }
  224.     else if (i_ptr->p1 > 0 || f_ptr->light) {
  225.         if (!(i_ptr->flags2 & TR_LIGHT))
  226.         i_ptr->p1--;       /* don't dec if perm light -CFT */
  227.         player_light = TRUE;
  228.         disturb(0, 1);
  229.     /* light creatures */
  230.         creatures(FALSE);
  231.     }
  232.     /* Update counters and messages    */
  233.     /* Check food status           */
  234.     regen_amount = PLAYER_REGEN_NORMAL;
  235.     if (f_ptr->food < PLAYER_FOOD_ALERT) {
  236.         if (f_ptr->food < PLAYER_FOOD_WEAK) {
  237.         if (f_ptr->food < 0)
  238.             regen_amount = 0;
  239.         else if (f_ptr->food < PLAYER_FOOD_FAINT)
  240.             regen_amount = PLAYER_REGEN_FAINT;
  241.         else if (f_ptr->food < PLAYER_FOOD_WEAK)
  242.             regen_amount = PLAYER_REGEN_WEAK;
  243.         if ((PY_WEAK & f_ptr->status) == 0) {
  244.             f_ptr->status |= PY_WEAK;
  245.             msg_print("You are getting weak from hunger.");
  246.             disturb(0, 0);
  247.             prt_hunger();
  248.         }
  249.         if ((f_ptr->food < PLAYER_FOOD_FAINT) && (randint(8) == 1)) {
  250.             f_ptr->paralysis += randint(5);
  251.             msg_print("You faint from the lack of food.");
  252.             disturb(1, 0);
  253.         }
  254.         } else if ((PY_HUNGRY & f_ptr->status) == 0) {
  255.         f_ptr->status |= PY_HUNGRY;
  256.         msg_print("You are getting hungry.");
  257.         disturb(0, 0);
  258.         prt_hunger();
  259.         }
  260.     }
  261.  
  262.     /* Food consumption     */
  263.     /* Note: Speeded up characters really burn up the food!  */
  264.     /* now summation, not square, since spd less powerful -CFT */
  265.        if (f_ptr->speed < 0)
  266.        f_ptr->food -=  (f_ptr->speed*f_ptr->speed - f_ptr->speed) / 2;
  267.     f_ptr->food -= f_ptr->food_digested;
  268.     if (f_ptr->food < 0) {
  269.         take_hit(-f_ptr->food / 16, "starvation");    /* -CJS- */
  270.         disturb(1, 0);
  271.     }
  272.  
  273.     /* Regenerate           */
  274.     if (f_ptr->regenerate)
  275.         regen_amount = regen_amount * 3 / 2;
  276.     if ((py.flags.status & PY_SEARCH) || f_ptr->rest > 0 ||
  277.         f_ptr->rest == -1 || f_ptr->rest == -2)
  278.         regen_amount = regen_amount * 2;
  279.     if ((py.flags.poisoned < 1) && (py.flags.cut < 1) &&
  280.         (p_ptr->chp < p_ptr->mhp))
  281.         regenhp(regen_amount);
  282.     if (p_ptr->cmana < p_ptr->mana)
  283.         regenmana(regen_amount);
  284.     /* Blindness           */
  285.     if (f_ptr->blind > 0) {
  286.         if ((PY_BLIND & f_ptr->status) == 0) {
  287.         f_ptr->status |= PY_BLIND;
  288.         prt_map();
  289.         prt_blind();
  290.         disturb(0, 1);
  291.         /* unlight creatures */
  292.         creatures(FALSE);
  293.         }
  294.         f_ptr->blind--;
  295.         if (f_ptr->blind == 0) {
  296.         f_ptr->status &= ~PY_BLIND;
  297.         prt_blind();
  298.         prt_map();
  299.         /* light creatures */
  300.         disturb(0, 1);
  301.         creatures(FALSE);
  302.         msg_print("The veil of darkness lifts.");
  303.         }
  304.     }
  305.     /* Confusion           */
  306.     if (f_ptr->confused > 0) {
  307.         if ((PY_CONFUSED & f_ptr->status) == 0) {
  308.         f_ptr->status |= PY_CONFUSED;
  309.         prt_confused();
  310.         }
  311.         f_ptr->confused--;
  312.         if (f_ptr->confused == 0) {
  313.         f_ptr->status &= ~PY_CONFUSED;
  314.         prt_confused();
  315.         msg_print("You feel less confused now.");
  316.         if (py.flags.rest > 0 || py.flags.rest == -1)
  317.             rest_off();
  318.         }
  319.     }
  320.     /* Afraid               */
  321.     if (f_ptr->afraid > 0) {
  322.         if ((PY_FEAR & f_ptr->status) == 0) {
  323.         if ((f_ptr->shero + f_ptr->hero + py.flags.fear_resist) > 0)
  324.             f_ptr->afraid = 0;
  325.         else {
  326.             f_ptr->status |= PY_FEAR;
  327.             prt_afraid();
  328.         }
  329.         } else if ((f_ptr->shero + f_ptr->hero + py.flags.fear_resist) > 0)
  330.         f_ptr->afraid = 1;
  331.         f_ptr->afraid--;
  332.         if (f_ptr->afraid == 0) {
  333.         f_ptr->status &= ~PY_FEAR;
  334.         prt_afraid();
  335.         msg_print("You feel bolder now.");
  336.         disturb(0, 0);
  337.         }
  338.     }
  339.     /* Cut */
  340.     if (f_ptr->cut > 0) {
  341.         if (f_ptr->cut>1000) {
  342.         take_hit(3 , "a fatal wound");
  343.         disturb(1,0);
  344.         } else if (f_ptr->cut>200) {
  345.         take_hit(3, "a fatal wound");
  346.         f_ptr->cut-=(con_adj()<0?1:con_adj())+1;
  347.         disturb(1,0);
  348.         } else if (f_ptr->cut>100) {
  349.         take_hit(2, "a fatal wound");
  350.         f_ptr->cut-=(con_adj()<0?1:con_adj())+1;
  351.         disturb(1,0);
  352.         } else {
  353.         take_hit(1, "a fatal wound");
  354.         f_ptr->cut-=(con_adj()<0?1:con_adj())+1;
  355.         disturb(1,0);
  356.         }
  357.         prt_cut();
  358.         if (f_ptr->cut <= 0) {
  359.         f_ptr->cut = 0;
  360.         if (py.misc.chp >= 0)
  361.             msg_print("Your wound heals.");
  362.         }
  363.     }
  364.     prt_cut();
  365.  
  366.     /* Stun */
  367.     if (f_ptr->stun > 0) {
  368.         int                 oldstun = f_ptr->stun;
  369.  
  370.         f_ptr->stun -= (con_adj() <= 0 ? 1 : (con_adj() / 2 + 1));
  371.                 /* fixes endless stun if bad con. -CFT */
  372.         if ((oldstun > 50) && (f_ptr->stun <= 50)) { 
  373.                 /* if crossed 50 mark... */
  374.         p_ptr->ptohit += 15;
  375.         p_ptr->ptodam += 15;
  376.         p_ptr->dis_th += 15;
  377.         p_ptr->dis_td += 15;
  378.         }
  379.         if (f_ptr->stun <= 0) {
  380.         f_ptr->stun = 0;
  381.         msg_print("Your head stops stinging.");
  382.         p_ptr->ptohit += 5;
  383.         p_ptr->ptodam += 5;
  384.         p_ptr->dis_th += 5;
  385.         p_ptr->dis_td += 5;
  386.         }
  387.     }
  388.     prt_stun();
  389.  
  390.     /* Poisoned           */
  391.     if (f_ptr->poisoned > 0) {
  392.         if ((PY_POISONED & f_ptr->status) == 0) {
  393.         f_ptr->status |= PY_POISONED;
  394.         prt_poisoned();
  395.         }
  396.         f_ptr->poisoned--;
  397.         if (f_ptr->poisoned == 0 || f_ptr->poison_im ||
  398.         f_ptr->poison_resist || f_ptr->resist_poison) {
  399.         f_ptr->poisoned = 0;
  400.         f_ptr->status &= ~PY_POISONED;
  401.         prt_poisoned();
  402.         msg_print("You feel better.");
  403.         disturb(0, 0);
  404.         } else {
  405.         switch (con_adj()) {
  406.           case -4:
  407.             i = 4;
  408.             break;
  409.           case -3:
  410.           case -2:
  411.             i = 3;
  412.             break;
  413.           case -1:
  414.             i = 2;
  415.             break;
  416.           case 0:
  417.             i = 1;
  418.             break;
  419.           case 1:
  420.           case 2:
  421.           case 3:
  422.             i = ((turn % 2) == 0);
  423.             break;
  424.           case 4:
  425.           case 5:
  426.             i = ((turn % 3) == 0);
  427.             break;
  428.           case 6:
  429.             i = ((turn % 4) == 0);
  430.             break;
  431.           case 7:
  432.             i = ((turn % 5) == 0);
  433.             break;
  434.           default:
  435.             i = ((turn % 6) == 0);
  436.             break;
  437.         }
  438.         take_hit(i, "poison");
  439.         disturb(1, 0);
  440.         }
  441.     }
  442.     /* Fast               */
  443.     if (f_ptr->fast > 0) {
  444.         if ((PY_FAST & f_ptr->status) == 0) {
  445.         f_ptr->status |= PY_FAST;
  446.         change_speed(-1);
  447.         msg_print("You feel yourself moving faster.");
  448.         disturb(0, 0);
  449.         }
  450.         f_ptr->fast--;
  451.         if (f_ptr->fast == 0) {
  452.         f_ptr->status &= ~PY_FAST;
  453.         change_speed(1);
  454.         msg_print("You feel yourself slow down.");
  455.         disturb(0, 0);
  456.         }
  457.     }
  458.     /* Slow               */
  459.     if (f_ptr->slow > 0) {
  460.         if ((PY_SLOW & f_ptr->status) == 0) {
  461.         f_ptr->status |= PY_SLOW;
  462.         change_speed(1);
  463.         msg_print("You feel yourself moving slower.");
  464.         disturb(0, 0);
  465.         }
  466.         f_ptr->slow--;
  467.         if (f_ptr->slow == 0) {
  468.         f_ptr->status &= ~PY_SLOW;
  469.         change_speed(-1);
  470.         msg_print("You feel yourself speed up.");
  471.         disturb(0, 0);
  472.         }
  473.     }
  474.     /* Resting is over?      */
  475.     if (f_ptr->rest > 0 || f_ptr->rest == -1 || f_ptr->rest == -2) {
  476.         if (f_ptr->rest > 0) {
  477.         f_ptr->rest--;
  478.         if (f_ptr->rest == 0)    /* Resting over */
  479.             rest_off();
  480.         } else if (f_ptr->rest == -1) {
  481.         if (py.misc.chp == py.misc.mhp && py.misc.cmana == py.misc.mana) {
  482.             f_ptr->rest = 0;
  483.             rest_off();
  484.         }
  485.         } else if (f_ptr->rest == -2) {    /* rest until
  486.                          * blind/conf/stun/
  487.                          * HP/mana/fear/halluc over */
  488.         if ((py.flags.blind < 1) && (py.flags.confused < 1) &&
  489.             (py.flags.afraid < 1) && (py.flags.stun < 1) &&
  490.             (py.flags.image < 1) && (py.flags.word_recall < 1) &&
  491.             (py.flags.slow < 1) && (py.misc.chp == py.misc.mhp) &&
  492.             (py.misc.cmana == py.misc.mana)) {
  493.             f_ptr->rest = 0;
  494.             rest_off();
  495.         }
  496.         }
  497.     }
  498.     /* Check for interrupts to find or rest. */
  499.     if ((command_count > 0 || find_flag || f_ptr->rest > 0 || f_ptr->rest == -1
  500.          || f_ptr->rest == -2)
  501. #if defined(MSDOS) || defined(VMS) /* stolen from Um55 src -CFT */
  502.         && kbhit()
  503. #else
  504.         && (check_input(find_flag ? 0 : 10000))
  505. #endif
  506.         ) {
  507. #ifdef MSDOS
  508.         (void)msdos_getch();
  509. #endif
  510. #ifdef VMS
  511.     /* Get and ignore the key used to interrupt resting/running.  */
  512.         (void)vms_getch();
  513. #endif
  514.         disturb(0, 0);
  515.     }
  516.     /* Hallucinating?     (Random characters appear!) */
  517.     if (f_ptr->image > 0) {
  518.         end_find();
  519.         f_ptr->image--;
  520.         if (f_ptr->image == 0)
  521.         prt_map();       /* Used to draw entire screen! -CJS- */
  522.     }
  523.     /* Paralysis           */
  524.     if (f_ptr->paralysis > 0) {
  525.     /* when paralysis true, you can not see any movement that occurs */
  526.         f_ptr->paralysis--;
  527.         disturb(1, 0);
  528.     }
  529.     /* Protection from evil counter */
  530.     if (f_ptr->protevil > 0) {
  531.         f_ptr->protevil--;
  532.         if (f_ptr->protevil == 0)
  533.         msg_print("You no longer feel safe from evil.");
  534.     }
  535.     /* Invulnerability     */
  536.     if (f_ptr->invuln > 0) {
  537.         if ((PY_INVULN & f_ptr->status) == 0) {
  538.         f_ptr->status |= PY_INVULN;
  539.         disturb(0, 0);
  540.         py.misc.ptoac += 100;    /* changed to ptoac -CFT */
  541.         py.misc.dis_tac += 100;
  542.         msg_print("Your skin turns to steel!");
  543.         f_ptr->status |= PY_ARMOR;    /* have to update ac display */
  544.         }
  545.         f_ptr->invuln--;
  546.         if (f_ptr->invuln == 0) {
  547.         f_ptr->status &= ~PY_INVULN;
  548.         disturb(0, 0);
  549.         py.misc.ptoac -= 100;    /* changed to ptoac -CFT */
  550.         py.misc.dis_tac -= 100;
  551.         msg_print("Your skin returns to normal.");
  552.         f_ptr->status |= PY_ARMOR;    /* have to update ac display */
  553.         }
  554.     }
  555.     /* Heroism       */
  556.     if (f_ptr->hero > 0) {
  557.         if ((PY_HERO & f_ptr->status) == 0) {
  558.         f_ptr->status |= PY_HERO;
  559.         disturb(0, 0);
  560.         p_ptr->mhp += 10;
  561.         p_ptr->chp += 10;
  562.         p_ptr->ptohit += 12;
  563.         p_ptr->dis_th += 12;
  564.         msg_print("You feel like a HERO!");
  565.         prt_mhp();
  566.         prt_chp();
  567.         }
  568.         f_ptr->hero--;
  569.         if (f_ptr->hero == 0) {
  570.         f_ptr->status &= ~PY_HERO;
  571.         disturb(0, 0);
  572.         p_ptr->mhp -= 10;
  573.         if (p_ptr->chp > p_ptr->mhp) {
  574.             p_ptr->chp = p_ptr->mhp;
  575.             p_ptr->chp_frac = 0;
  576.             prt_chp();
  577.         }
  578.         p_ptr->ptohit -= 12;
  579.         p_ptr->dis_th -= 12;
  580.         msg_print("The heroism wears off.");
  581.         prt_mhp();
  582.         }
  583.     }
  584.     /* Super Heroism */
  585.     if (f_ptr->shero > 0) {
  586.         if ((PY_SHERO & f_ptr->status) == 0) {
  587.         f_ptr->status |= PY_SHERO;
  588.         disturb(0, 0);
  589.         p_ptr->mhp += 30;
  590.         p_ptr->chp += 30;
  591.         p_ptr->ptohit += 24;
  592.         p_ptr->dis_th += 24;
  593.         p_ptr->ptoac -= 10;
  594.         p_ptr->dis_tac -= 10;
  595.         msg_print("You feel like a killing machine!");
  596.         prt_mhp();
  597.         prt_chp();
  598.         f_ptr->status |= PY_ARMOR;    /* have to update ac display */
  599.         }
  600.         f_ptr->shero--;
  601.         if (f_ptr->shero == 0) {
  602.         f_ptr->status &= ~PY_SHERO;
  603.         disturb(0, 0);
  604.         p_ptr->mhp -= 30;
  605.         p_ptr->ptoac += 10;
  606.         p_ptr->dis_tac += 10;
  607.         if (p_ptr->chp > p_ptr->mhp) {
  608.             p_ptr->chp = p_ptr->mhp;
  609.             p_ptr->chp_frac = 0;
  610.             prt_chp();
  611.         }
  612.         p_ptr->ptohit -= 24;
  613.         p_ptr->dis_th -= 24;
  614.         msg_print("You feel less Berserk.");
  615.         prt_mhp();
  616.         f_ptr->status |= PY_ARMOR;    /* have to update ac display */
  617.         }
  618.     }
  619.     /* Blessed       */
  620.     if (f_ptr->blessed > 0) {
  621.         if ((PY_BLESSED & f_ptr->status) == 0) {
  622.         f_ptr->status |= PY_BLESSED;
  623.         disturb(0, 0);
  624.         p_ptr->ptohit += 10;
  625.         p_ptr->dis_th += 10;
  626.         p_ptr->ptoac += 5; /* changed to ptoac -CFT */
  627.         p_ptr->dis_tac += 5;
  628.         msg_print("You feel righteous!");
  629.         f_ptr->status |= PY_ARMOR;    /* have to update ac display */
  630.         }
  631.         f_ptr->blessed--;
  632.         if (f_ptr->blessed == 0) {
  633.         f_ptr->status &= ~PY_BLESSED;
  634.         disturb(0, 0);
  635.         p_ptr->ptohit -= 10;
  636.         p_ptr->dis_th -= 10;
  637.         p_ptr->ptoac -= 5; /* changed to ptoac -CFT */
  638.         p_ptr->dis_tac -= 5;
  639.         msg_print("The prayer has expired.");
  640.         f_ptr->status |= PY_ARMOR;    /* have to update ac display */
  641.         }
  642.     }
  643.     /* Shield       */
  644.     if (f_ptr->shield > 0) {
  645.         f_ptr->shield--;
  646.         if (f_ptr->shield == 0) {
  647.         disturb(0, 0);
  648.         msg_print("Your mystic shield crumbles away.");
  649.         py.misc.ptoac -= 50;    /* changed to ptoac -CFT */
  650.         py.misc.dis_tac -= 50;
  651.         f_ptr->status |= PY_ARMOR;    /* have to update ac display */
  652.         }
  653.     }
  654.     /* Resist Heat   */
  655.     if (f_ptr->resist_heat > 0) {
  656.         f_ptr->resist_heat--;
  657.         if (f_ptr->resist_heat == 0)
  658.         msg_print("You no longer feel safe from flame.");
  659.     }
  660.     /* Resist Cold   */
  661.     if (f_ptr->resist_cold > 0) {
  662.         f_ptr->resist_cold--;
  663.         if (f_ptr->resist_cold == 0)
  664.         msg_print("You no longer feel safe from cold.");
  665.     }
  666.     /* Resist Acid   */
  667.     if (f_ptr->resist_acid > 0) {
  668.         f_ptr->resist_acid--;
  669.         if (f_ptr->resist_acid == 0)
  670.         msg_print("You no longer feel safe from acid.");
  671.     }
  672.     /* Resist Lightning   */
  673.     if (f_ptr->resist_light > 0) {
  674.         f_ptr->resist_light--;
  675.         if (f_ptr->resist_light == 0)
  676.         msg_print("You no longer feel safe from lightning.");
  677.     }
  678.     /* Resist Poison   */
  679.     if (f_ptr->resist_poison > 0) {
  680.         f_ptr->resist_poison--;
  681.         if (f_ptr->resist_poison == 0)
  682.         msg_print("You no longer feel safe from poison.");
  683.     }
  684.     /* Timeout Artifacts  */
  685.     for (i = 22; i < (INVEN_ARRAY_SIZE - 1); i++) {
  686.         i_ptr = &inventory[i];
  687.         if (i_ptr->tval != TV_NOTHING && (i_ptr->flags2 & TR_ACTIVATE)) {
  688.         if (i_ptr->timeout > 0)
  689.             i_ptr->timeout--;
  690.         if ((i_ptr->tval == TV_RING) &&
  691.             (!stricmp(object_list[i_ptr->index].name, "Power")) &&
  692.             (randint(20) == 1) && (py.misc.exp > 0))
  693.             py.misc.exp--, py.misc.max_exp--, prt_experience();
  694.         }
  695.     }
  696.  
  697.     /* Timeout rods  */
  698.     for (i = 0; i < 22; i++) {
  699.         i_ptr = &inventory[i];
  700.         if (i_ptr->tval == TV_ROD && (i_ptr->flags2 & TR_ACTIVATE)) {
  701.         if (i_ptr->timeout > 0)
  702.             i_ptr->timeout--;
  703.         }
  704.     }
  705.  
  706.     /* Detect Invisible      */
  707.     if (f_ptr->detect_inv > 0) {
  708.         if ((PY_DET_INV & f_ptr->status) == 0) {
  709.         f_ptr->status |= PY_DET_INV;
  710.         f_ptr->see_inv = TRUE;
  711.         /* light but don't move creatures */
  712.         creatures(FALSE);
  713.         }
  714.         f_ptr->detect_inv--;
  715.         if (f_ptr->detect_inv == 0) {
  716.         f_ptr->status &= ~PY_DET_INV;
  717.         /* may still be able to see_inv if wearing magic item */
  718.         if (py.misc.prace == 9)
  719.             f_ptr->see_inv = TRUE;
  720.         else {
  721.             f_ptr->see_inv = FALSE;    /* unless item grants it */
  722.             for (i = INVEN_WIELD; i <= INVEN_LIGHT; i++)
  723.             if (TR_SEE_INVIS & inventory[i].flags)
  724.                 f_ptr->see_inv = TRUE;
  725.         }
  726.         /* unlight but don't move creatures */
  727.         creatures(FALSE);
  728.         }
  729.     }
  730.     /* Timed infra-vision    */
  731.     if (f_ptr->tim_infra > 0) {
  732.         if ((PY_TIM_INFRA & f_ptr->status) == 0) {
  733.         f_ptr->status |= PY_TIM_INFRA;
  734.         f_ptr->see_infra++;
  735.         /* light but don't move creatures */
  736.         creatures(FALSE);
  737.         }
  738.         f_ptr->tim_infra--;
  739.         if (f_ptr->tim_infra == 0) {
  740.         f_ptr->status &= ~PY_TIM_INFRA;
  741.         f_ptr->see_infra--;
  742.         /* unlight but don't move creatures */
  743.         creatures(FALSE);
  744.         }
  745.     }
  746.     /* Word-of-Recall  Note: Word-of-Recall is a delayed action     */
  747.     if (f_ptr->word_recall > 0)
  748.         if (f_ptr->word_recall == 1) {
  749.         new_level_flag = TRUE;
  750.         f_ptr->paralysis++;
  751.         f_ptr->word_recall = 0;
  752.         if (dun_level > 0) {
  753.             dun_level = 0;
  754.             msg_print("You feel yourself yanked upwards! ");
  755.         } else if (py.misc.max_dlv != 0) {
  756.             dun_level = py.misc.max_dlv;
  757.             msg_print("You feel yourself yanked downwards! ");
  758.         }
  759.         } else
  760.         f_ptr->word_recall--;
  761.  
  762.     /* Random teleportation  */
  763.     if ((py.flags.teleport) && (randint(100) == 1)) {
  764.         disturb(0, 0);
  765.         teleport(40);
  766.     }
  767.     /* See if we are too weak to handle the weapon or pack.  -CJS- */
  768.     if (py.flags.status & PY_STR_WGT)
  769.         check_strength();
  770.     if (py.flags.status & PY_STUDY)
  771.         prt_study();
  772.     if (py.flags.status & PY_SPEED) {
  773.         py.flags.status &= ~PY_SPEED;
  774.         prt_speed();
  775.     }
  776.     if ((py.flags.status & PY_PARALYSED) && (py.flags.paralysis < 1)) {
  777.         prt_state();
  778.         py.flags.status &= ~PY_PARALYSED;
  779.     } else if (py.flags.paralysis > 0) {
  780.         prt_state();
  781.         py.flags.status |= PY_PARALYSED;
  782.     } else if (py.flags.rest > 0 || py.flags.rest == -1 || py.flags.rest == -2)
  783.         prt_state();
  784.  
  785.     if ((py.flags.status & PY_ARMOR) != 0) {
  786.         py.misc.dis_ac = py.misc.pac + py.misc.dis_tac;    /* use updated ac */
  787.         prt_pac();
  788.         py.flags.status &= ~PY_ARMOR;
  789.     }
  790.     if ((py.flags.status & PY_STATS) != 0) {
  791.         for (i = 0; i < 6; i++)
  792.         if ((PY_STR << i) & py.flags.status)
  793.             prt_stat(i);
  794.         py.flags.status &= ~PY_STATS;
  795.     }
  796.     if (py.flags.status & PY_HP) {
  797.         prt_mhp();
  798.         prt_chp();
  799.         py.flags.status &= ~PY_HP;
  800.     }
  801.     if (py.flags.status & PY_MANA) {
  802.         prt_cmana();
  803.         py.flags.status &= ~PY_MANA;
  804.     }
  805.     /* Allow for a slim chance of detect enchantment -CJS- */
  806.     /*
  807.      * for 1st level char, check once every 2160 turns for 40th level char,
  808.      * check once every 416 turns 
  809.      */
  810.     if (py.misc.pclass == 2 ?
  811.         ((f_ptr->confused == 0) && (py.misc.pclass != 0) &&
  812.     (randint((int)(10000 / (py.misc.lev * py.misc.lev + 40)) + 1) == 1))
  813.         :
  814.         (((turn & 0xF) == 0) && (f_ptr->confused == 0)
  815.          && (randint((int)(10 + 750 / (5 + py.misc.lev))) == 1))
  816.         ) {
  817.         vtype               tmp_str;
  818.  
  819.         for (i = 0; i < INVEN_ARRAY_SIZE; i++) {
  820.         if (i == inven_ctr)
  821.             i = 22;
  822.         i_ptr = &inventory[i];
  823.  
  824.         /*
  825.          * if in inventory, succeed 1 out of 50 times, if in equipment
  826.          * list, success 1 out of 10 times, unless you're a priest or
  827.          * rogue... 
  828.          */
  829.         if (((i_ptr->tval >= TV_MIN_WEAR) && (i_ptr->tval <= TV_MAX_WEAR)) &&
  830.             special_check(i_ptr) &&
  831.             ((py.misc.pclass == 2 || py.misc.pclass == 3) ?
  832.              (randint(i < 22 ? 5 : 1) == 1) :
  833.              (randint(i < 22 ? 50 : 10) == 1))) {
  834.  
  835.             if (py.misc.pclass == 0 || py.misc.pclass == 3 ||
  836.             py.misc.pclass == 5)
  837.             if ((i_ptr->tval == TV_SWORD) ||
  838.                 (i_ptr->tval == TV_HAFTED) ||
  839.                 (i_ptr->tval == TV_POLEARM) ||
  840.                 (i_ptr->tval == TV_BOW) ||
  841.                 (i_ptr->tval == TV_BOLT) ||
  842.                 (i_ptr->tval == TV_ARROW) ||
  843.                 (i_ptr->tval == TV_DIGGING) ||
  844.                 (i_ptr->tval == TV_SLING_AMMO) ||
  845.                 (i_ptr->tval == TV_SOFT_ARMOR) ||
  846.                 (i_ptr->tval == TV_HARD_ARMOR) ||
  847.                 (i_ptr->tval == TV_HELM) ||
  848.                 (i_ptr->tval == TV_BOOTS) ||
  849.                 (i_ptr->tval == TV_CLOAK) ||
  850.                 (i_ptr->tval == TV_GLOVES) ||
  851.                 (i_ptr->tval == TV_SHIELD))
  852.                 continue;
  853.             (void)sprintf(tmp_str,
  854.                 "There's something %s about what you are %s...",
  855.                   special_check(i_ptr) > 0 ? "good" : "bad",
  856.                   describe_use(i));
  857.             disturb(0, 0);
  858.             msg_print(tmp_str);
  859.             add_inscribe(i_ptr, (special_check(i_ptr) > 0) ?
  860.                  ID_MAGIK : ID_DAMD);
  861.         }
  862.         }
  863.     }
  864.     /* Warriors, Rogues and paladins inbuilt ident */
  865.     if (((py.misc.pclass == 0) && (f_ptr->confused == 0) &&
  866.      (randint((int)(9000 / (py.misc.lev * py.misc.lev + 40)) + 1) == 1))
  867.         ||
  868.         ((py.misc.pclass == 3) && (f_ptr->confused == 0) &&
  869.     (randint((int)(20000 / (py.misc.lev * py.misc.lev + 40)) + 1) == 1))
  870.         ||
  871.         ((py.misc.pclass == 5) && (f_ptr->confused == 0) &&
  872.          (randint((int)(80000L / (py.misc.lev * py.misc.lev + 40)) + 1) == 1))) {
  873.         vtype               tmp_str;
  874.  
  875.         for (i = 0; i < INVEN_ARRAY_SIZE; i++) {
  876.         if (i == inven_ctr)
  877.             i = 22;
  878.         i_ptr = &inventory[i];
  879.         /*
  880.          * if in inventory, succeed 1 out of 5 times, if in equipment
  881.          * list, always succeed! 
  882.          */
  883.         if (((i_ptr->tval == TV_SOFT_ARMOR) ||
  884.              (i_ptr->tval == TV_HARD_ARMOR) ||
  885.              (i_ptr->tval == TV_SWORD) ||
  886.              (i_ptr->tval == TV_HAFTED) ||
  887.              (i_ptr->tval == TV_POLEARM) ||
  888.              (i_ptr->tval == TV_SHIELD) ||
  889.              (i_ptr->tval == TV_HELM) ||
  890.              (i_ptr->tval == TV_BOOTS) ||
  891.              (i_ptr->tval == TV_GLOVES) ||
  892.              (i_ptr->tval == TV_DIGGING) ||
  893.              (i_ptr->tval == TV_SLING_AMMO) ||
  894.              (i_ptr->tval == TV_BOLT) ||
  895.              (i_ptr->tval == TV_ARROW) ||
  896.              (i_ptr->tval == TV_BOW) ||
  897.              (i_ptr->tval == TV_CLOAK))
  898.             && value_check(i_ptr) &&
  899.             (randint(i < 22 ? 5 : 1) == 1)) {
  900.             char                out_val[100], tmp[100], *ptr;
  901.             int                 sp;
  902.  
  903.             (void)strcpy(tmp, object_list[i_ptr->index].name);
  904.  
  905.             ptr = tmp;
  906.             sp = 0;
  907.             while (tmp[sp] == ' ' || tmp[sp] == '&')
  908.             ptr = &tmp[++sp];
  909.  
  910.             (void)strcpy(out_val, ptr);
  911.  
  912.             ptr = out_val;
  913.  
  914.             while (*ptr) {
  915.             if (*ptr == '~')
  916.                 *ptr = 's';
  917.             ptr++;
  918.             }
  919.  
  920.             (void)sprintf(tmp_str,
  921.                   "You feel the %s (%c) you are %s %s %s...",
  922.                   out_val,
  923.             ((i < INVEN_WIELD) ? i + 'a' : (i + 'a' - INVEN_WIELD)),
  924.                   describe_use(i),
  925.                   ((i_ptr->tval == TV_BOLT) ||
  926.                    (i_ptr->tval == TV_ARROW) ||
  927.                    (i_ptr->tval == TV_SLING_AMMO) ||
  928.                    (i_ptr->tval == TV_BOOTS) ||
  929.                  (i_ptr->tval == TV_GLOVES)) ? "are" : "is",
  930.                   value_check(i_ptr));
  931.             disturb(0, 0);
  932.             msg_print(tmp_str);
  933.             if (!stricmp(value_check(i_ptr), "terrible"))
  934.             add_inscribe(i_ptr, ID_DAMD);
  935.             else if (!stricmp(value_check(i_ptr), "worthless"))
  936.             add_inscribe(i_ptr, ID_DAMD);
  937.             else
  938.             inscribe(i_ptr, value_check(i_ptr));
  939.         }
  940.         }
  941.     }
  942.     /*
  943.      * Check the state of the monster list, and delete some monsters if the
  944.      * monster list is nearly full.  This helps to avoid problems in
  945.      * creature.c when monsters try to multiply.  Compact_monsters() is much
  946.      * more likely to succeed if called from here, than if called from within
  947.      * creatures().  
  948.      */
  949.     if (MAX_MALLOC - mfptr < 10)
  950.         (void)compact_monsters();
  951.  
  952.     if ((py.flags.paralysis < 1) &&    /* Accept a command?     */
  953.         (py.flags.rest == 0) &&
  954.         (py.flags.stun < 100) &&
  955.         (!death))
  956.     /* Accept a command and execute it                 */
  957.     {
  958.         do {
  959.         if (py.flags.status & PY_REPEAT)
  960.             prt_state();
  961.         default_dir = FALSE;
  962.         free_turn_flag = FALSE;
  963.  
  964.         if ((old_rad >= 0) && (!find_flag)) {
  965.             light_rad = old_rad;
  966.             old_rad = (-1);
  967.         }
  968.         if (find_flag) {
  969.             find_run();
  970.             find_count--;
  971.             if (find_count == 0)
  972.             end_find();
  973.             put_qio();
  974.         } else if (doing_inven)
  975.             inven_command(doing_inven);
  976.         else {
  977.         /* move the cursor to the players character */
  978.             move_cursor_relative(char_row, char_col);
  979.             if (command_count > 0) {
  980.             command_count--;
  981.             msg_flag = FALSE;
  982.             default_dir = TRUE;
  983.             } else {
  984. #ifdef TARGET
  985. /* This bit of targetting code taken from Morgul -CFT */
  986. /* If we are in targetting mode, with a creature target, make the targetted */
  987. /* row and column match the creature's.  This optimizes a lot of code.  CDW */
  988.             if ((target_mode)&&(target_mon<(unsigned) mfptr)) {
  989.                 target_row = m_list[target_mon].fy;
  990.                 target_col = m_list[target_mon].fx;
  991.             }
  992. #endif
  993.             msg_flag = FALSE;
  994.             command = inkey();
  995.             i = 0;
  996.             /* Get a count for a command. */
  997.             if ((rogue_like_commands
  998.                  && command >= '0' && command <= '9')
  999.                 || (!rogue_like_commands && command == '#')) {
  1000.                 char                tmp[8];
  1001.  
  1002.                 prt("Repeat count:", 0, 0);
  1003.                 if (command == '#')
  1004.                 command = '0';
  1005.                 i = 0;
  1006.                 while (TRUE) {
  1007.                 if (command == DELETE || command == CTRL('H')) {
  1008.                     i = i / 10;
  1009.                     (void)sprintf(tmp, "%d", i);
  1010.                     prt(tmp, 0, 14);
  1011.                 } else if (command >= '0' && command <= '9') {
  1012.                     if (i > 99)
  1013.                     bell();
  1014.                     else {
  1015.                     i = i * 10 + command - '0';
  1016.                     (void)sprintf(tmp, "%d", i);
  1017.                     prt(tmp, 0, 14);
  1018.                     }
  1019.                 } else
  1020.                     break;
  1021.                 command = inkey();
  1022.                 }
  1023.                 if (i == 0) {
  1024.                 i = 99;
  1025.                 (void)sprintf(tmp, "%d", i);
  1026.                 prt(tmp, 0, 14);
  1027.                 }
  1028.             /* a special hack to allow numbers as commands */
  1029.                 if (command == ' ') {
  1030.                 prt("Command:", 0, 20);
  1031.                 command = inkey();
  1032.                 }
  1033.             }
  1034.             /* Another way of typing control codes -CJS- */
  1035.             if (command == '^') {
  1036.                 if (command_count > 0)
  1037.                 prt_state();
  1038.                 if (get_com("Control-", &command)) {
  1039.                 if (command >= 'A' && command <= 'Z')
  1040.                     command -= 'A' - 1;
  1041.                 else if (command >= 'a' && command <= 'z')
  1042.                     command -= 'a' - 1;
  1043.                 else {
  1044.                     msg_print("Type ^ <letter> for a control char");
  1045.                     command = ' ';
  1046.                 }
  1047.                 } else
  1048.                 command = ' ';
  1049.             }
  1050.             /* move cursor to player char again, in case it moved */
  1051.             move_cursor_relative(char_row, char_col);
  1052.             /* Commands are always converted to rogue form. -CJS- */
  1053.             if (rogue_like_commands == FALSE)
  1054.                 command = original_commands(command);
  1055.             if (i > 0) {
  1056.                 if (!valid_countcommand(command)) {
  1057.                 free_turn_flag = TRUE;
  1058.                 msg_print("Invalid command with a count.");
  1059.                 command = ' ';
  1060.                 } else {
  1061.                 command_count = i;
  1062.                 prt_state();
  1063.                 command_count--;    /* count this pass as
  1064.                              * one */
  1065.                 }
  1066.             }
  1067.             }
  1068.         /* Flash the message line. */
  1069.             erase_line(MSG_LINE, 0);
  1070.             move_cursor_relative(char_row, char_col);
  1071.             put_qio();
  1072.  
  1073.             do_command(command);
  1074.         /* Find is counted differently, as the command changes. */
  1075.             if (find_flag) {
  1076.             find_count = command_count;
  1077.             command_count = 0;
  1078.             } else if (old_rad >= 0) {
  1079.             light_rad = old_rad;
  1080.             old_rad = (-1);
  1081.             }
  1082.             if (free_turn_flag)
  1083.             command_count = 0;
  1084.         }
  1085.         /* End of commands                     */
  1086.         }
  1087.         while (free_turn_flag && !new_level_flag && !eof_flag);
  1088.     } else {
  1089.     /* if paralyzed, resting, or dead, flush output */
  1090.     /* but first move the cursor onto the player, for aesthetics */
  1091.         move_cursor_relative(char_row, char_col);
  1092.         put_qio();
  1093.     }
  1094.  
  1095.     /* Teleport?               */
  1096.     if (teleport_flag)
  1097.         teleport(100);
  1098.     /* Move the creatures           */
  1099.     if (!new_level_flag)
  1100.         creatures(TRUE);
  1101.     /* Exit when new_level_flag is set   */
  1102.     }
  1103.     while (!new_level_flag && !eof_flag);
  1104. }
  1105.  
  1106.  
  1107. static char 
  1108. original_commands(com_val)
  1109. char com_val;
  1110. {
  1111.     int dir_val;
  1112.  
  1113.     switch (com_val) {
  1114.       case CTRL('K'):        /* ^K = exit    */
  1115.     com_val = 'Q';
  1116.     break;
  1117.       case CTRL('J'):        /* not used */
  1118.       case CTRL('M'):        /* not used */
  1119.         com_val = ' ';
  1120.     break;
  1121.       case CTRL('F'):        /* ^F = repeat feeling */
  1122.       case CTRL('R'):        /* ^R = redraw screen  */
  1123.       case CTRL('P'):        /* ^P = repeat  */
  1124.       case CTRL('W'):        /* ^W = enter wizard mode */
  1125.       case CTRL('X'):        /* ^X = save    */
  1126.       case ' ':
  1127.     break;
  1128.       case '.': {
  1129. #ifdef TARGET
  1130. /* If in target_mode, player will not be given a chance to pick a direction.
  1131.  * So we save it, force it off, and then ask for the direction -CFT */
  1132.       int temp = target_mode;
  1133.       target_mode = FALSE;
  1134. #endif
  1135.       if (get_dir(NULL, &dir_val))
  1136.         switch (dir_val) {
  1137.           case 1:
  1138.         com_val = 'B';
  1139.         break;
  1140.           case 2:
  1141.         com_val = 'J';
  1142.         break;
  1143.           case 3:
  1144.         com_val = 'N';
  1145.         break;
  1146.           case 4:
  1147.         com_val = 'H';
  1148.         break;
  1149.           case 6:
  1150.         com_val = 'L';
  1151.         break;
  1152.           case 7:
  1153.         com_val = 'Y';
  1154.         break;
  1155.           case 8:
  1156.         com_val = 'K';
  1157.         break;
  1158.           case 9:
  1159.         com_val = 'U';
  1160.         break;
  1161.           default:
  1162.         com_val = ' ';
  1163.         break;
  1164.         }
  1165.     else
  1166.         com_val = ' ';
  1167. #ifdef TARGET
  1168.       target_mode = temp; /* restore old target code ... -CFT */
  1169. #endif
  1170.         }
  1171.     break;
  1172.       case '/':
  1173.       case '<':
  1174.       case '>':
  1175.       case '-':
  1176.       case '=':
  1177.       case '{':
  1178.       case '?':
  1179.       case 'A':
  1180.     break;
  1181.       case '1':
  1182.     com_val = 'b';
  1183.     break;
  1184.       case '2':
  1185.     com_val = 'j';
  1186.     break;
  1187.       case '3':
  1188.     com_val = 'n';
  1189.     break;
  1190.       case '4':
  1191.     com_val = 'h';
  1192.     break;
  1193.       case '5':            /* Rest one turn */
  1194.     com_val = '.';
  1195.     break;
  1196.       case '6':
  1197.     com_val = 'l';
  1198.     break;
  1199.       case '7':
  1200.     com_val = 'y';
  1201.     break;
  1202.       case '8':
  1203.     com_val = 'k';
  1204.     break;
  1205.       case '9':
  1206.     com_val = 'u';
  1207.     break;
  1208.       case 'B':
  1209.     com_val = 'f';
  1210.     break;
  1211.       case 'C':
  1212.       case 'D':
  1213.       case 'E':
  1214.       case 'F':
  1215.       case 'G':
  1216.       case 'g':
  1217.     break;
  1218.       case 'L':
  1219.     com_val = 'W';
  1220.     break;
  1221.       case 'M':
  1222.       case 'R':
  1223.     break;
  1224.       case 'S':
  1225.     com_val = '#';
  1226.     break;
  1227.       case 'T': {
  1228. #ifdef TARGET
  1229. /* If in target_mode, player will not be given a chance to pick a direction.
  1230.  * So we save it, force it off, and then ask for the direction -CFT
  1231.  */
  1232.     int temp = target_mode;
  1233.     target_mode = FALSE;
  1234. #endif
  1235.     if (get_dir(NULL, &dir_val))
  1236.         switch (dir_val) {
  1237.           case 1:
  1238.         com_val = CTRL('B');
  1239.         break;
  1240.           case 2:
  1241.         com_val = CTRL('J');
  1242.         break;
  1243.           case 3:
  1244.         com_val = CTRL('N');
  1245.         break;
  1246.           case 4:
  1247.         com_val = CTRL('H');
  1248.         break;
  1249.           case 6:
  1250.         com_val = CTRL('L');
  1251.         break;
  1252.           case 7:
  1253.         com_val = CTRL('Y');
  1254.         break;
  1255.           case 8:
  1256.         com_val = CTRL('K');
  1257.         break;
  1258.           case 9:
  1259.         com_val = CTRL('U');
  1260.         break;
  1261.           default:
  1262.         com_val = ' ';
  1263.         break;
  1264.         }
  1265.     else
  1266.         com_val = ' ';
  1267. #ifdef TARGET
  1268.       target_mode = temp;
  1269. #endif
  1270.         }
  1271.     break;
  1272.       case 'a':
  1273.     com_val = 'z';
  1274.     break;
  1275.       case 'b':
  1276.     com_val = 'P';
  1277.     break;
  1278.       case 'c':
  1279.       case 'd':
  1280.       case 'e':
  1281.     break;
  1282.       case 'f':
  1283.     com_val = 't';
  1284.     break;
  1285.       case 'h':
  1286.     com_val = '?';
  1287.     break;
  1288.       case 'i':
  1289.     break;
  1290.       case 'j':
  1291.     com_val = 'S';
  1292.     break;
  1293.       case 'l':
  1294.     com_val = 'x';
  1295.     break;
  1296.       case 'm':
  1297.       case 'o':
  1298.       case 'p':
  1299.       case 'q':
  1300.       case 'r':
  1301.       case 's':
  1302.     break;
  1303.       case 't':
  1304.     com_val = 'T';
  1305.     break;
  1306.       case 'u':
  1307.     com_val = 'Z';
  1308.     break;
  1309.       case 'z':
  1310.     com_val = 'a';
  1311.     break;
  1312.       case 'v':
  1313.       case 'V':
  1314.       case 'w':
  1315.     break;
  1316.       case 'x':
  1317.     com_val = 'X';
  1318.     break;
  1319.  
  1320.     /* wizard mode commands follow */
  1321.       case '\\':        /* \ = wizard help */
  1322.       case CTRL('A'):        /* ^A = cure all */
  1323.       case CTRL('D'):        /* ^D = up/down */
  1324.       case CTRL('E'):        /* ^E = wizchar */
  1325.       case CTRL('G'):        /* ^G = treasure */
  1326.       case CTRL('I'):        /* ^I = identify */
  1327.       case CTRL('O'):        /* ^O = generate objects */
  1328.       case CTRL('T'):        /* ^T = teleport */
  1329.       case CTRL('V'):        /* ^V = treasure */
  1330.       case CTRL('Z'):        /* ^Z = genocide */
  1331.       case ':':            /* map area */
  1332.       case '~':            /* artifact list to file */
  1333.       case '!':            /* rerate hitpoints */
  1334.       case '@':            /* create object */
  1335.       case '$':            /* wiz. light */
  1336.       case '%':            /* '%' == self knowledge */
  1337.       case '&':            /* & = summon  */
  1338.       case '*':            /* Indentify up to level */
  1339.       case '+':            /* add experience */
  1340.       case '|':            /* check uniques - cba */
  1341.     break;
  1342.       default:
  1343.     com_val = '(';        /* Anything illegal. */
  1344.     break;
  1345.     }
  1346.     return com_val;
  1347. }
  1348.  
  1349. /* Is an item an enchanted weapon or armor and we don't know?  -CJS- */
  1350. /* returns positive if it is a good enchantment */
  1351. /* returns negative if a bad enchantment... */
  1352. int 
  1353. special_check(t_ptr)
  1354. register inven_type *t_ptr;
  1355. {
  1356.     if (t_ptr->tval == TV_NOTHING)
  1357.     return 0;
  1358.     if (known2_p(t_ptr))
  1359.     return 0;
  1360.     if (store_bought_p(t_ptr))
  1361.     return 0;
  1362.     if (t_ptr->ident & ID_MAGIK)
  1363.     return 0;
  1364.     if (t_ptr->ident & ID_DAMD)
  1365.     return 0;
  1366.     if (t_ptr->flags & TR_CURSED)
  1367.     return -1;
  1368.     if (t_ptr->tval != TV_HARD_ARMOR && t_ptr->tval != TV_SWORD &&
  1369.     t_ptr->tval != TV_SOFT_ARMOR && t_ptr->tval != TV_SHIELD &&
  1370.     t_ptr->tval != TV_CLOAK && t_ptr->tval != TV_GLOVES &&
  1371.     t_ptr->tval != TV_BOOTS && t_ptr->tval != TV_HELM &&
  1372.     t_ptr->tval != TV_DIGGING && t_ptr->tval != TV_SPIKE &&
  1373.     t_ptr->tval != TV_SLING_AMMO && t_ptr->tval != TV_BOLT &&
  1374.     t_ptr->tval != TV_ARROW && t_ptr->tval != TV_BOW &&
  1375.     t_ptr->tval != TV_POLEARM && t_ptr->tval != TV_HAFTED)
  1376.     return 0;
  1377.     if (t_ptr->tohit > 0 || t_ptr->todam > 0 || t_ptr->toac > 0)
  1378.     return 1;
  1379.     if ((t_ptr->tval == TV_DIGGING) && /* digging tools will pseudo ID, either
  1380.                       as {good} or {average} -CFT */
  1381.     (t_ptr->flags & TR_TUNNEL))
  1382.     return 1;
  1383.  
  1384.     return 0;
  1385. }
  1386.  
  1387.  
  1388. /* Is an item an enchanted weapon or armor and we don't know?  -CJS- */
  1389. /* returns a description */
  1390. static const char *
  1391. value_check(t_ptr)
  1392. register inven_type *t_ptr;
  1393. {
  1394.     if (t_ptr->tval == TV_NOTHING)
  1395.     return 0;
  1396.     if (known2_p(t_ptr))
  1397.     return 0;
  1398.     if (store_bought_p(t_ptr))
  1399.     return 0;
  1400.     if (t_ptr->ident & ID_MAGIK)
  1401.     return 0;
  1402.     if (t_ptr->ident & ID_DAMD)
  1403.     return 0;
  1404.     if (t_ptr->inscrip[0] != '\0')
  1405.     return 0;
  1406.     if (t_ptr->flags & TR_CURSED && t_ptr->name2 == SN_NULL)
  1407.     return "worthless";
  1408.     if (t_ptr->flags & TR_CURSED && t_ptr->name2 != SN_NULL)
  1409.     return "terrible";
  1410.     if ((t_ptr->tval == TV_DIGGING) &&  /* also, good digging tools -CFT */
  1411.     (t_ptr->flags & TR_TUNNEL) &&
  1412.     (t_ptr->p1 > object_list[t_ptr->index].p1)) /* better than normal for this
  1413.                                type of shovel/pick? -CFT */
  1414.     return "good";
  1415.     if ((t_ptr->tohit<=0 && t_ptr->todam<=0 && t_ptr->toac<=0) &&
  1416.     t_ptr->name2==SN_NULL)  /* normal shovels will also reach here -CFT */
  1417.     return "average";
  1418.     if (t_ptr->name2 == SN_NULL)
  1419.     return "good";
  1420.     if ((t_ptr->name2 == SN_R) || (t_ptr->name2 == SN_RA) ||
  1421.     (t_ptr->name2 == SN_RF) || (t_ptr->name2 == SN_RC) ||
  1422.     (t_ptr->name2 == SN_RL) || (t_ptr->name2 == SN_SE) ||
  1423.     (t_ptr->name2 == SN_HA) || (t_ptr->name2 == SN_FT) ||
  1424.     (t_ptr->name2 == SN_DF) || (t_ptr->name2 == SN_FB) ||
  1425.     (t_ptr->name2 == SN_SA) || (t_ptr->name2 == SN_FREE_ACTION) ||
  1426.     (t_ptr->name2 == SN_SD) || (t_ptr->name2 == SN_SLAYING) ||
  1427.     (t_ptr->name2 == SN_SU) || (t_ptr->name2 == SN_SLOW_DESCENT) ||
  1428.     (t_ptr->name2 == SN_SPEED) || (t_ptr->name2 == SN_STEALTH) ||
  1429.     (t_ptr->name2 == SN_INTELLIGENCE) || (t_ptr->name2 == SN_WISDOM) ||
  1430.     (t_ptr->name2 == SN_INFRAVISION) || (t_ptr->name2 == SN_MIGHT) ||
  1431.     (t_ptr->name2 == SN_LORDLINESS) || (t_ptr->name2 == SN_MAGI) ||
  1432.     (t_ptr->name2 == SN_BEAUTY) || (t_ptr->name2 == SN_SEEING) ||
  1433.      (t_ptr->name2 == SN_REGENERATION) || (t_ptr->name2 == SN_PROTECTION) ||
  1434.     (t_ptr->name2 == SN_FIRE) || (t_ptr->name2 == SN_SLAY_EVIL) ||
  1435.     (t_ptr->name2 == SN_DRAGON_SLAYING) || (t_ptr->name2 == SN_SLAY_ANIMAL) ||
  1436.     (t_ptr->name2 == SN_ACCURACY) || (t_ptr->name2 == SN_SO) ||
  1437.     (t_ptr->name2 == SN_POWER) || (t_ptr->name2 == SN_WEST) ||
  1438.     (t_ptr->name2 == SN_SDEM) || (t_ptr->name2 == SN_ST) ||
  1439.     (t_ptr->name2 == SN_LIGHT) || (t_ptr->name2 == SN_AGILITY) ||
  1440.     (t_ptr->name2 == SN_SG) || (t_ptr->name2 == SN_TELEPATHY) ||
  1441.     (t_ptr->name2 == SN_DRAGONKIND) || (t_ptr->name2 == SN_AMAN) ||
  1442.     (t_ptr->name2 == SN_ELVENKIND) || (t_ptr->name2 == SN_WOUNDING) ||
  1443.     (t_ptr->name2 == SN_BLESS_BLADE) || (t_ptr->name2 == SN_ATTACKS))
  1444.     return "excellent";
  1445.     return "special";
  1446. }
  1447.  
  1448. static void 
  1449. do_command(com_val)
  1450. char com_val;
  1451. {
  1452.     int                    dir_val, do_pickup;
  1453.     int                    y, x, i, j = 0;
  1454.     vtype                  out_val, tmp_str;
  1455.     register struct flags *f_ptr;
  1456.     char                   prt1[80];
  1457.  
  1458. /* hack for move without pickup.  Map '-' to a movement command. */
  1459.     if (com_val == '-') {
  1460.     do_pickup = FALSE;
  1461.     i = command_count;
  1462. #ifdef TARGET
  1463.     {
  1464. /* If in target_mode, player will not be given a chance to pick a direction.
  1465.  * So we save it, force it off, and then ask for the direction -CFT
  1466.  */
  1467.     int temp = target_mode;
  1468.     target_mode = FALSE;
  1469. #endif
  1470.     if (get_dir(NULL, &dir_val)) {
  1471.         command_count = i;
  1472.         switch (dir_val) {
  1473.           case 1:
  1474.         com_val = 'b';
  1475.         break;
  1476.           case 2:
  1477.         com_val = 'j';
  1478.         break;
  1479.           case 3:
  1480.         com_val = 'n';
  1481.         break;
  1482.           case 4:
  1483.         com_val = 'h';
  1484.         break;
  1485.           case 6:
  1486.         com_val = 'l';
  1487.         break;
  1488.           case 7:
  1489.         com_val = 'y';
  1490.         break;
  1491.           case 8:
  1492.         com_val = 'k';
  1493.         break;
  1494.           case 9:
  1495.         com_val = 'u';
  1496.         break;
  1497.           default:
  1498.         com_val = '(';
  1499.         break;
  1500.         }
  1501.     } else
  1502.         com_val = ' ';
  1503. #ifdef TARGET
  1504.     target_mode = temp;
  1505.     }
  1506. #endif
  1507.     } else
  1508.     do_pickup = TRUE;
  1509.  
  1510.     switch (com_val) {
  1511.       case 'Q':            /* (Q)uit        (^K)ill */
  1512.     flush();
  1513.     if ((!total_winner) ? get_Yn("Do you really want to quit?")
  1514.         : get_Yn("Do you want to retire?")) {
  1515.         new_level_flag = TRUE;
  1516.         death = TRUE;
  1517.         (void)strcpy(died_from, "Quitting");
  1518.     }
  1519.     free_turn_flag = TRUE;
  1520.     break;
  1521.       case CTRL('P'):        /* (^P)revious message. */
  1522.     if (command_count > 0) {
  1523.         i = command_count;
  1524.         if (i > MAX_SAVE_MSG)
  1525.         i = MAX_SAVE_MSG;
  1526.         command_count = 0;
  1527.     } else if (last_command != 16)
  1528.         i = 1;
  1529.     else
  1530.         i = MAX_SAVE_MSG;
  1531.     j = last_msg;
  1532.     if (i > 1) {
  1533.         save_screen();
  1534.         x = i;
  1535.         while (i > 0) {
  1536.         i--;
  1537.         prt(old_msg[j], i, 0);
  1538.         if (j == 0)
  1539.             j = MAX_SAVE_MSG - 1;
  1540.         else
  1541.             j--;
  1542.         }
  1543.         erase_line(x, 0);
  1544.         pause_line(x);
  1545.         restore_screen();
  1546.     } else {
  1547.     /* Distinguish real and recovered messages with a '>'. -CJS- */
  1548.         put_buffer(">", 0, 0);
  1549.         prt(old_msg[j], 0, 1);
  1550.     }
  1551.     free_turn_flag = TRUE;
  1552.     break;
  1553.       case CTRL('F'):        /* Repeat (^F)eeling */
  1554.     free_turn_flag = TRUE;
  1555.     print_feeling();
  1556.     break;
  1557.       case CTRL('W'):        /* (^W)izard mode */
  1558.     if (wizard) {
  1559.         wizard = FALSE;
  1560.         msg_print("Wizard mode off.");
  1561.     } else if (enter_wiz_mode())
  1562.         msg_print("Wizard mode on.");
  1563.     prt_winner();
  1564.     free_turn_flag = TRUE;
  1565.     break;
  1566.       case CTRL('X'):        /* e(^X)it and save */
  1567.     if (total_winner) {
  1568.         msg_print("You are a Total Winner,  your character must be retired.");
  1569.         if (rogue_like_commands)
  1570.         msg_print("Use 'Q' to when you are ready to retire.");
  1571.         else
  1572.         msg_print("Use <Control>-K when you are ready to retire.");
  1573.     } else {
  1574.         (void)strcpy(died_from, "(saved)");
  1575.         msg_print("Saving game...");
  1576.         if (save_char())
  1577.         exit_game();
  1578.         msg_print("Save failed...");
  1579.         (void)strcpy(died_from, "(alive and well)");
  1580.     }
  1581.     free_turn_flag = TRUE;
  1582.     break;
  1583.       case CTRL('R'):
  1584.     if (py.flags.image > 0)
  1585.         msg_print("You cannot be sure what is real and what is not!");
  1586.     else {
  1587.         draw_cave();
  1588.         creatures(FALSE);      /* draw monsters */
  1589.         prt_equippy_chars();  /* redraw equippy chars */
  1590.     }
  1591.     free_turn_flag = TRUE;
  1592.     break;
  1593. #ifdef TARGET
  1594. /* select a target (sorry, no intuitive letter keys were left: a/A for aim,
  1595.  * t/T for target, f/F for focus, s/S for select, c/C for choose and p/P for pick
  1596.  *  were all already taken.  Wiz light command moved to '$', which was unused. -CFT
  1597.  */
  1598.       case '*':
  1599.     target();        /* target code taken from Morgul -CFT */
  1600.     free_turn_flag = TRUE;
  1601.     break;                
  1602. #endif
  1603.       case '=':            /* (=) set options */
  1604.     save_screen();
  1605.     set_options();
  1606.     restore_screen();
  1607.     free_turn_flag = TRUE;
  1608.     break;
  1609.       case '{':            /* ({) inscribe an object    */
  1610.     scribe_object();
  1611.     free_turn_flag = TRUE;
  1612.     break;
  1613.       case '!':            /* (!) escape to the shell */
  1614.     if (!wizard)
  1615. #ifdef MSDOS            /* Let's be a little more accurate... */
  1616.         msg_print("Sorry, Angband doesn't leave enough free memory for a subshell.");
  1617. #else
  1618.         msg_print("Sorry, inferior shells are not allowed from ANGBAND.");
  1619. #endif
  1620.     else
  1621.         rerate();
  1622.     free_turn_flag = TRUE;
  1623.     break;
  1624.       case ESCAPE:        /* (ESC)   do nothing. */
  1625.       case ' ':            /* (space) do nothing. */
  1626.     free_turn_flag = TRUE;
  1627.     break;
  1628.       case 'b':            /* (b) down, left    (1) */
  1629.     move_char(1, do_pickup);
  1630.     break;
  1631.       case 'j':            /* (j) down        (2) */
  1632.     move_char(2, do_pickup);
  1633.     break;
  1634.       case 'n':            /* (n) down, right    (3) */
  1635.     move_char(3, do_pickup);
  1636.     break;
  1637.       case 'h':            /* (h) left        (4) */
  1638.     move_char(4, do_pickup);
  1639.     break;
  1640.       case 'l':            /* (l) right        (6) */
  1641.     move_char(6, do_pickup);
  1642.     break;
  1643.       case 'y':            /* (y) up, left        (7) */
  1644.     move_char(7, do_pickup);
  1645.     break;
  1646.       case 'k':            /* (k) up        (8) */
  1647.     move_char(8, do_pickup);
  1648.     break;
  1649.       case 'u':            /* (u) up, right    (9) */
  1650.     move_char(9, do_pickup);
  1651.     break;
  1652.       case 'B':            /* (B) run down, left    (. 1) */
  1653.     find_init(1);
  1654.     break;
  1655.       case 'J':            /* (J) run down        (. 2) */
  1656.     find_init(2);
  1657.     break;
  1658.       case 'N':            /* (N) run down, right    (. 3) */
  1659.     find_init(3);
  1660.     break;
  1661.       case 'H':            /* (H) run left        (. 4) */
  1662.     find_init(4);
  1663.     break;
  1664.       case 'L':            /* (L) run right    (. 6) */
  1665.     find_init(6);
  1666.     break;
  1667.       case 'Y':            /* (Y) run up, left    (. 7) */
  1668.     find_init(7);
  1669.     break;
  1670.       case 'K':            /* (K) run up        (. 8) */
  1671.     find_init(8);
  1672.     break;
  1673.       case 'U':            /* (U) run up, right    (. 9) */
  1674.     find_init(9);
  1675.     break;
  1676.       case '/':            /* (/) identify a symbol */
  1677.     ident_char();
  1678.     free_turn_flag = TRUE;
  1679.     break;
  1680.       case '.':            /* (.) stay in one place (5) */
  1681.     move_char(5, do_pickup);
  1682.     if (command_count > 1) {
  1683.         command_count--;
  1684.         rest();
  1685.     }
  1686.     break;
  1687.       case '<':            /* (<) go down a staircase */
  1688.     go_up();
  1689.     break;
  1690.       case '>':            /* (>) go up a staircase */
  1691.     go_down();
  1692.     break;
  1693.       case '?':            /* (?) help with commands */
  1694.     if (rogue_like_commands)
  1695.         helpfile(ANGBAND_HELP);
  1696.     else
  1697.         helpfile(ANGBAND_ORIG_HELP);
  1698.     free_turn_flag = TRUE;
  1699.     break;
  1700. #ifdef ALLOW_SCORE
  1701.       case 'v':   /* score patch originally by Mike Welsh mikewe@acacia.cs.pdx.edu */
  1702.     sprintf(prt1,"Your current score is: %ld", total_points());
  1703.     msg_print(prt1);
  1704.     break;
  1705. #endif
  1706.       case 'f':            /* (f)orce        (B)ash */
  1707.     bash();
  1708.     break;
  1709.       case 'A':            /* (A)ctivate        (A)ctivate */
  1710.     activate();
  1711.     break;
  1712.       case 'C':            /* (C)haracter description */
  1713.     save_screen();
  1714.     change_name();
  1715.     restore_screen();
  1716.     free_turn_flag = TRUE;
  1717.     break;
  1718.       case 'D':            /* (D)isarm trap */
  1719.     disarm_trap();
  1720.     break;
  1721.       case 'E':            /* (E)at food */
  1722.     eat();
  1723.     break;
  1724.       case 'F':            /* (F)ill lamp */
  1725.     refill_lamp();
  1726.     break;
  1727.       case 'G':            /* (G)ain magic spells */
  1728.     gain_spells();
  1729.     break;
  1730.       case 'g':            /* (g)et an object... */
  1731.     if (prompt_carry_flag) {
  1732.         if (cave[char_row][char_col].tptr != 0)    /* minor change -CFT */
  1733.         carry(char_row, char_col, TRUE);
  1734.     } else
  1735.         free_turn_flag = TRUE;
  1736.     break;
  1737.       case 'W':            /* (W)here are we on the map    (L)ocate on map */
  1738.     if ((py.flags.blind > 0) || no_light())
  1739.         msg_print("You can't see your map.");
  1740.     else {
  1741.         int                 cy, cx, p_y, p_x;
  1742. #ifdef TARGET
  1743. /* If in target_mode, player will not be given a chance to pick a direction.
  1744.  * So we save it, force it off, and then ask for the direction -CFT
  1745.  */
  1746.         int temp = target_mode;
  1747.         target_mode = FALSE;
  1748. #endif
  1749.  
  1750.         y = char_row;
  1751.         x = char_col;
  1752.         if (get_panel(y, x, TRUE))
  1753.         prt_map();
  1754.         cy = panel_row;
  1755.         cx = panel_col;
  1756.         for (;;) {
  1757.         p_y = panel_row;
  1758.         p_x = panel_col;
  1759.         if (p_y == cy && p_x == cx)
  1760.             tmp_str[0] = '\0';
  1761.         else
  1762.             (void)sprintf(tmp_str, "%s%s of",
  1763.                  p_y < cy ? " North" : p_y > cy ? " South" : "",
  1764.                   p_x < cx ? " West" : p_x > cx ? " East" : "");
  1765.         (void)sprintf(out_val,
  1766.       "Map sector [%d,%d], which is%s your sector. Look which direction?",
  1767.                   p_y, p_x, tmp_str);
  1768.         if (!get_dir(out_val, &dir_val))
  1769.             break;
  1770.  
  1771. /* -CJS- Should really use the move function, but what the hell. This is nicer,
  1772.  * as it moves exactly to the same place in another section. The direction
  1773.  * calculation is not intuitive. Sorry.
  1774.  */
  1775.         for (;;) {
  1776.             x += ((dir_val - 1) % 3 - 1) * SCREEN_WIDTH / 2;
  1777.             y -= ((dir_val - 1) / 3 - 1) * SCREEN_HEIGHT / 2;
  1778.             if (x < 0 || y < 0 || x >= cur_width || y >= cur_width) {
  1779.             msg_print("You've gone past the end of your map.");
  1780.             x -= ((dir_val - 1) % 3 - 1) * SCREEN_WIDTH / 2;
  1781.             y += ((dir_val - 1) / 3 - 1) * SCREEN_HEIGHT / 2;
  1782.             break;
  1783.             }
  1784.             if (get_panel(y, x, TRUE)) {
  1785.             prt_map();
  1786.             break;
  1787.             }
  1788.         }
  1789.         }
  1790.     /* Move to a new panel - but only if really necessary. */
  1791.         if (get_panel(char_row, char_col, FALSE))
  1792.         prt_map();
  1793. #ifdef TARGET
  1794.         target_mode = temp; /* restore target mode... */
  1795. #endif
  1796.     }
  1797.     free_turn_flag = TRUE;
  1798.     break;
  1799.       case 'R':            /* (R)est a while */
  1800.     rest();
  1801.     break;
  1802.       case '#':            /* (#) search toggle    (S)earch toggle */
  1803.     if (py.flags.status & PY_SEARCH)
  1804.         search_off();
  1805.     else
  1806.         search_on();
  1807.     free_turn_flag = TRUE;
  1808.     break;
  1809.       case CTRL('B'):        /* (^B) tunnel down left    (T 1) */
  1810.     tunnel(1);
  1811.     break;
  1812.       case CTRL('M'):        /* cr must be treated same as lf. */
  1813.       case CTRL('J'):        /* (^J) tunnel down        (T 2) */
  1814.     tunnel(2);
  1815.     break;
  1816.       case CTRL('N'):        /* (^N) tunnel down right    (T 3) */
  1817.     tunnel(3);
  1818.     break;
  1819.       case CTRL('H'):        /* (^H) tunnel left        (T 4) */
  1820.     tunnel(4);
  1821.     break;
  1822.       case CTRL('L'):        /* (^L) tunnel right        (T 6) */
  1823.     tunnel(6);
  1824.     break;
  1825.       case CTRL('Y'):        /* (^Y) tunnel up left        (T 7) */
  1826.     tunnel(7);
  1827.     break;
  1828.       case CTRL('K'):        /* (^K) tunnel up        (T 8) */
  1829.     tunnel(8);
  1830.     break;
  1831.       case CTRL('U'):        /* (^U) tunnel up right        (T 9) */
  1832.     tunnel(9);
  1833.     break;
  1834.       case 'z':            /* (z)ap a wand        (a)im a wand */
  1835.     aim();
  1836.     break;
  1837.       case 'a':            /* (a)ctivate a rod    (z)ap a rod */
  1838.     activate_rod();
  1839.     break;
  1840.       case 'M':
  1841.     screen_map();
  1842.     free_turn_flag = TRUE;
  1843.     break;
  1844.       case 'P':            /* (P)eruse a book    (B)rowse in a book */
  1845.     examine_book();
  1846.     free_turn_flag = TRUE;
  1847.     break;
  1848.       case 'c':            /* (c)lose an object */
  1849.     closeobject();
  1850.     break;
  1851.       case 'd':            /* (d)rop something */
  1852.     inven_command('d');
  1853.     break;
  1854.       case 'e':            /* (e)quipment list */
  1855.     inven_command('e');
  1856.     break;
  1857.       case 't':            /* (t)hrow something    (f)ire something */
  1858.     throw_object();
  1859.     break;
  1860.       case 'i':            /* (i)nventory list */
  1861.     inven_command('i');
  1862.     break;
  1863.       case 'S':            /* (S)pike a door    (j)am a door */
  1864.     jamdoor();
  1865.     break;
  1866.       case 'x':            /* e(x)amine surrounds    (l)ook about */
  1867.     look();
  1868.     free_turn_flag = TRUE;
  1869.     break;
  1870.       case 'm':            /* (m)agic spells */
  1871.     cast();
  1872.     break;
  1873.       case 'o':            /* (o)pen something */
  1874.     openobject();
  1875.     break;
  1876.       case 'p':            /* (p)ray */
  1877.     pray();
  1878.     break;
  1879.       case 'q':            /* (q)uaff */
  1880.     quaff();
  1881.     break;
  1882.       case 'r':            /* (r)ead */
  1883.     read_scroll();
  1884.     break;
  1885.       case 's':            /* (s)earch for a turn */
  1886.     search(char_row, char_col, py.misc.srh);
  1887.     break;
  1888.       case 'T':            /* (T)ake off something    (t)ake off */
  1889.     inven_command('t');
  1890.     break;
  1891.       case 'Z':            /* (Z)ap a staff    (u)se a staff */
  1892.     use();
  1893.     break;
  1894.       case 'V':            /* (V)ersion of game */
  1895.     helpfile(ANGBAND_VER);
  1896.     free_turn_flag = TRUE;
  1897.     break;
  1898.       case 'w':            /* (w)ear or wield */
  1899.     inven_command('w');
  1900.     break;
  1901.       case 'X':            /* e(X)change weapons    e(x)change */
  1902.     inven_command('x');
  1903.     break;
  1904. #ifdef ALLOW_ARTIFACT_CHECK /* -CWS */
  1905.       case '~':
  1906.     if ((!wizard) && (dun_level != 0)) {
  1907.         msg_print("You need to be on the town level to check artifacts!");
  1908.         msg_print(NULL);        /* make sure can see the message -CWS */
  1909.     } else
  1910.         artifact_check_no_file();
  1911.     break;
  1912. #endif
  1913. #ifdef ALLOW_CHECK_UNIQUES /* -CWS */
  1914.       case '|':
  1915.     check_uniques();
  1916.     break;
  1917. #endif
  1918.       default:
  1919.     if (wizard) {
  1920.         free_turn_flag = TRUE; /* Wizard commands are free moves */
  1921.         switch (com_val) {
  1922.           case '\\':       /* \ wizard help */
  1923.         helpfile(ANGBAND_WIZ_HELP);
  1924.           case CTRL('A'):       /* ^A = Cure all */
  1925.         (void)remove_all_curse();
  1926.         (void)cure_blindness();
  1927.         (void)cure_confusion();
  1928.         (void)cure_poison();
  1929.         (void)remove_fear();
  1930.         (void)res_stat(A_STR);
  1931.         (void)res_stat(A_INT);
  1932.         (void)res_stat(A_WIS);
  1933.         (void)res_stat(A_CON);
  1934.         (void)res_stat(A_DEX);
  1935.         (void)res_stat(A_CHR);
  1936.         (void)restore_level();
  1937.         (void)hp_player(2000);
  1938.         py.flags.food = PLAYER_FOOD_MAX;
  1939.         f_ptr = &py.flags;
  1940.         if (f_ptr->slow > 1)
  1941.             f_ptr->slow = 1;
  1942.         if (f_ptr->image > 1)
  1943.             f_ptr->image = 1;
  1944.         if (f_ptr->cut > 1)
  1945.             f_ptr->cut = 1;
  1946.         if (f_ptr->stun > 1)
  1947.             f_ptr->stun = 1;
  1948.         break;
  1949.           case CTRL('D'):    /* ^D = up/down */
  1950.         if (command_count > 0) {
  1951.             if (command_count > 99)
  1952.             i = 0;
  1953.             else
  1954.             i = command_count;
  1955.             command_count = 0;
  1956.         } else {
  1957.             prt("Go to which level (0-10000) ? ", 0, 0);
  1958.             i = (-1);
  1959.             if (get_string(tmp_str, 0, 27, 10))
  1960.             i = atoi(tmp_str);
  1961.             if (i > 10000)
  1962.             i = 10000;
  1963.         }
  1964.         if (i > -1) {
  1965.             dun_level = i;
  1966.             if (dun_level > 10000)
  1967.             dun_level = 10000;
  1968.             new_level_flag = TRUE;
  1969.         } else
  1970.             erase_line(MSG_LINE, 0);
  1971.         break;
  1972.           case CTRL('E'):    /* ^E = wizchar */
  1973.         change_character();
  1974.         erase_line(MSG_LINE, 0); /* from um55 -CFT */
  1975.         break;
  1976.           case CTRL('G'):    /* ^G = treasure */
  1977.         if (command_count > 0) {
  1978.             i = command_count;
  1979.             command_count = 0;
  1980.         } else
  1981.             i = 1;
  1982.         random_object(char_row, char_col, i);
  1983.         prt_map();
  1984.         break;
  1985.           case CTRL('I'):    /* ^I = identify */
  1986.         (void)ident_spell();
  1987.         break;
  1988.           case CTRL('O'):    /* ^O = objects */
  1989.         print_objects();
  1990.         break;
  1991.           case CTRL('T'):    /* ^T = teleport */
  1992.         teleport(100);
  1993.         break;
  1994.           case CTRL('V'):    /* ^V special treasure */
  1995.         if (command_count > 0) {
  1996.             i = command_count;
  1997.             command_count = 0;
  1998.         } else
  1999.             i = 1;
  2000.         special_random_object(char_row, char_col, i);
  2001.         prt_map();
  2002.         break;
  2003.           case CTRL('Z'):    /* ^Z = genocide */
  2004.         (void)mass_genocide(FALSE);
  2005.         break;
  2006.           case ':':
  2007.         map_area();
  2008.         break;
  2009.           case '~':
  2010.         artifact_check_no_file();
  2011.         break;
  2012.           case '|':
  2013.         check_uniques();
  2014.         break;
  2015.           case '@':
  2016.         wizard_create();
  2017.         break;
  2018.           case '$':       /* $ = wiz light */
  2019.         wizard_light(TRUE);
  2020.         break;
  2021.           case '%':       /* self-knowledge */
  2022.         self_knowledge();
  2023.         break;
  2024.           case '&':       /* & = summon  */
  2025.         y = char_row;
  2026.         x = char_col;
  2027.         (void)summon_monster(&y, &x, TRUE);
  2028.         creatures(FALSE);
  2029.         break;
  2030.           case '*':        /* '*' = identify all up to a level */
  2031.         prt("Identify objects upto which level (0-200) ? ", 0, 0);
  2032.         i = (-1);
  2033.         if (get_string(tmp_str, 0, 47, 10))
  2034.             i = atoi(tmp_str);
  2035.         if (i > 200)
  2036.             i = 200;
  2037.         if (i > -1) {
  2038.             int                 temp;
  2039.             inven_type          inv;
  2040.  
  2041.             for (temp = 0; temp < MAX_DUNGEON_OBJ; temp++) {
  2042.             if (object_list[temp].level <= i) {
  2043.                 invcopy(&inv, temp);
  2044.                 known1(&inv);
  2045.             }
  2046.             }
  2047.         }
  2048.         erase_line(MSG_LINE, 0);
  2049.         break;
  2050.           case '+':
  2051.         if (command_count > 0) {
  2052.             py.misc.exp = command_count;
  2053.             command_count = 0;
  2054.         } else if (py.misc.exp == 0)
  2055.             py.misc.exp = 1;
  2056.         else
  2057.             py.misc.exp = py.misc.exp * 2;
  2058.         prt_experience();
  2059.         break;
  2060.           default:
  2061.         prt("Type '?' or '\\' for help.", 0, 0);
  2062.         }
  2063.     } else {
  2064.         prt("Type '?' for help.", 0, 0);
  2065.         free_turn_flag = TRUE;
  2066.     }
  2067.     }
  2068.     last_command = com_val;
  2069. }
  2070.  
  2071. /* Check whether this command will accept a count.     -CJS-  */
  2072. static int 
  2073. valid_countcommand(c)
  2074. char c;
  2075. {
  2076.     switch (c) {
  2077.       case 'Q':
  2078.       case CTRL('W'):
  2079.       case CTRL('X'):
  2080.       case '=':
  2081.       case '{':
  2082.       case '/':
  2083.       case '<':
  2084.       case '>':
  2085.       case '?':
  2086.       case 'A':
  2087.       case 'C':
  2088.       case 'E':
  2089.       case 'F':
  2090.       case 'G':
  2091.       case '#':
  2092.       case 'z':
  2093.       case 'P':
  2094.       case 'c':
  2095.       case 'd':
  2096.       case 'e':
  2097.       case 't':
  2098.       case 'i':
  2099.       case 'x':
  2100.       case 'm':
  2101.       case 'p':
  2102.       case 'q':
  2103.       case 'r':
  2104.       case 'T':
  2105.       case 'Z':
  2106.       case 'V':
  2107.       case 'w':
  2108.       case 'W':
  2109.       case 'X':
  2110.       case CTRL('A'):
  2111.       case '\\':
  2112.       case CTRL('I'):
  2113.       case CTRL('^'):
  2114.       case '$':
  2115.       case '*':
  2116.       case ':':
  2117.       case CTRL('T'):
  2118.       case CTRL('E'):
  2119.       case CTRL('F'):
  2120.       case CTRL('Z'):
  2121.       case CTRL('S'):
  2122.       case CTRL('Q'):
  2123.       case CTRL('R'):
  2124.     return FALSE;
  2125.       case CTRL('P'):
  2126.       case ESCAPE:
  2127.       case ' ':
  2128.       case '-':
  2129.       case 'b':
  2130.       case 'f':
  2131.       case 'j':
  2132.       case 'n':
  2133.       case 'h':
  2134.       case 'l':
  2135.       case 'y':
  2136.       case 'k':
  2137.       case 'u':
  2138.       case '.':
  2139.       case 'B':
  2140.       case 'J':
  2141.       case 'N':
  2142.       case 'H':
  2143.       case 'L':
  2144.       case 'Y':
  2145.       case 'K':
  2146.       case 'U':
  2147.       case 'D':
  2148.       case 'R':
  2149.       case CTRL('Y'):
  2150.       case CTRL('K'):
  2151.       case CTRL('U'):
  2152.       case CTRL('L'):
  2153.       case CTRL('N'):
  2154.       case CTRL('J'):
  2155.       case CTRL('B'):
  2156.       case CTRL('H'):
  2157.       case 'S':
  2158.       case 'o':
  2159.       case 's':
  2160.       case CTRL('D'):
  2161.       case CTRL('G'):
  2162.       case '+':
  2163.     return TRUE;
  2164.       default:
  2165.     return FALSE;
  2166.     }
  2167. }
  2168.  
  2169.  
  2170. /* Regenerate hit points                -RAK-     */
  2171. static void 
  2172. regenhp(percent)
  2173. int percent;
  2174. {
  2175.     register struct misc *p_ptr;
  2176.     register int32        new_chp, new_chp_frac;
  2177.     int                   old_chp;
  2178.  
  2179.     p_ptr = &py.misc;
  2180.     old_chp = p_ptr->chp;
  2181.     new_chp = ((long)p_ptr->mhp) * percent + PLAYER_REGEN_HPBASE;
  2182.     p_ptr->chp += new_chp >> 16;   /* div 65536 */
  2183. /* check for overflow */
  2184.     if (p_ptr->chp < 0 && old_chp > 0)
  2185.     p_ptr->chp = MAX_SHORT;
  2186.     new_chp_frac = (new_chp & 0xFFFF) + p_ptr->chp_frac;    /* mod 65536 */
  2187.     if (new_chp_frac >= 0x10000L) {
  2188.     p_ptr->chp_frac = new_chp_frac - 0x10000L;
  2189.     p_ptr->chp++;
  2190.     } else
  2191.     p_ptr->chp_frac = new_chp_frac;
  2192.  
  2193. /* must set frac to zero even if equal */
  2194.     if (p_ptr->chp >= p_ptr->mhp) {
  2195.     p_ptr->chp = p_ptr->mhp;
  2196.     p_ptr->chp_frac = 0;
  2197.     }
  2198.     if (old_chp != p_ptr->chp)
  2199.     prt_chp();
  2200. }
  2201.  
  2202.  
  2203. /* Regenerate mana points                -RAK-     */
  2204. static void 
  2205. regenmana(percent)
  2206. int percent;
  2207. {
  2208.     register struct misc *p_ptr;
  2209.     register int32        new_mana, new_mana_frac;
  2210.     int                   old_cmana;
  2211.  
  2212.     p_ptr = &py.misc;
  2213.     old_cmana = p_ptr->cmana;
  2214.     new_mana = ((long)p_ptr->mana) * percent + PLAYER_REGEN_MNBASE;
  2215.     p_ptr->cmana += new_mana >> 16;/* div 65536 */
  2216. /* check for overflow */
  2217.     if (p_ptr->cmana < 0 && old_cmana > 0)
  2218.     p_ptr->cmana = MAX_SHORT;
  2219.     new_mana_frac = (new_mana & 0xFFFF) + p_ptr->cmana_frac;    /* mod 65536 */
  2220.     if (new_mana_frac >= 0x10000L) {
  2221.     p_ptr->cmana_frac = new_mana_frac - 0x10000L;
  2222.     p_ptr->cmana++;
  2223.     } else
  2224.     p_ptr->cmana_frac = new_mana_frac;
  2225.  
  2226. /* must set frac to zero even if equal */
  2227.     if (p_ptr->cmana >= p_ptr->mana) {
  2228.     p_ptr->cmana = p_ptr->mana;
  2229.     p_ptr->cmana_frac = 0;
  2230.     }
  2231.     if (old_cmana != p_ptr->cmana)
  2232.     prt_cmana();
  2233. }
  2234.  
  2235.  
  2236.  
  2237. int 
  2238. ruin_stat(stat)
  2239. register int stat;
  2240. {
  2241.     register int tmp_stat;
  2242.  
  2243.     tmp_stat = py.stats.cur_stat[stat];
  2244.     if (tmp_stat > 3) {
  2245.     if (tmp_stat > 6) {
  2246.         if (tmp_stat < 19) {
  2247.         tmp_stat -= 3;
  2248.         } else {
  2249.         tmp_stat /= 2;
  2250.         if (tmp_stat < 18)
  2251.             tmp_stat = 18;
  2252.         }
  2253.     } else
  2254.         tmp_stat--;
  2255.  
  2256.     py.stats.cur_stat[stat] = tmp_stat;
  2257.     py.stats.max_stat[stat] = tmp_stat;
  2258.     set_use_stat(stat);
  2259.     prt_stat(stat);
  2260.     return TRUE;
  2261.     } else
  2262.     return FALSE;
  2263. }
  2264.  
  2265. static void 
  2266. activate()
  2267. {
  2268.     int          i, a, flag, first, num, j, redraw, dir, test = FALSE;
  2269.     char         out_str[200], tmp[200], tmp2[200], choice;
  2270.     inven_type  *i_ptr;
  2271.     struct misc *m_ptr;
  2272.  
  2273.     flag = FALSE;
  2274.     redraw = FALSE;
  2275.     num = 0;
  2276.     first = 0;
  2277.     for (i = 22; i < (INVEN_ARRAY_SIZE - 1); i++) {
  2278.     if ((inventory[i].flags2 & TR_ACTIVATE) && (known2_p(&(inventory[i])))) {
  2279.         num++;
  2280.         if (!flag)
  2281.         first = i;
  2282.         flag = TRUE;
  2283.     }
  2284.     }
  2285.     if (!flag) {
  2286.     msg_print("You are not wearing/wielding anything that can be activated.");
  2287.     free_turn_flag = TRUE;
  2288.     return;
  2289.     }
  2290.     sprintf(out_str, "Activate which item? (%c-%c, * to list, ESC to exit) ?",
  2291.         'a', 'a' + (num - 1));
  2292.     flag = FALSE;
  2293.     while (!flag){
  2294.     if (!get_com(out_str, &choice))  /* on escape, get_com returns false: */
  2295.         choice = '\033';             /* so it's set here to ESC.  Wierd huh? -CFT */
  2296.  
  2297.     if ((choice=='*') && !redraw) {  /* don't save screen again if it's already
  2298.                       * listed, OW it doesn't clear -CFT */
  2299.         save_screen();
  2300.         j=0;
  2301.         if (!redraw) {
  2302.         for (i = first; i < (INVEN_ARRAY_SIZE - 1); i++) {
  2303.             if ((inventory[i].flags2 & TR_ACTIVATE) &&
  2304.             known2_p(&(inventory[i]))) {
  2305.             objdes(tmp2, &inventory[i], TRUE);
  2306.             sprintf(tmp, "%c) %-61s", 'a' + j, tmp2);
  2307.             erase_line(1 + j, 13);
  2308. /* we display at 15, but erase from 13 to give a couple of spaces,
  2309.  * so it looks tidy.  -CFT */
  2310.  
  2311.             sprintf(tmp, "%c) %-40s", 'a' + j, tmp2);
  2312.             prt(tmp, 1 + j, 15);
  2313. /* No need to check for bottom of screen, since only have 11 items in equip,
  2314.  * so will never reach bottom... -CFT */
  2315.             j++;
  2316.             }
  2317.         }
  2318.         redraw = TRUE;
  2319.         continue;
  2320.         }
  2321.     } else {
  2322.         if (choice >= 'A' && choice <= ('A' + (num - 1))) {
  2323.         choice -= 'A';
  2324.         test = TRUE; /* test to see if he means it */
  2325.         }
  2326.         else if (choice >= 'a' && choice <= ('a' + (num - 1)))
  2327.         choice -= 'a';
  2328.         else if (choice == '\033') {
  2329.         if (redraw) {
  2330.             restore_screen();
  2331.             redraw = FALSE;
  2332.         }
  2333.         free_turn_flag = TRUE;
  2334.         break;
  2335.         } else {
  2336.         bell();
  2337.         continue;       /* try another letter */
  2338.         }
  2339.  
  2340.         if (redraw) {
  2341.         restore_screen();
  2342.         redraw = FALSE;
  2343.         }
  2344.         if (choice > num)
  2345.         continue;
  2346.         flag = TRUE;
  2347.         j = 0;
  2348.         for (i = first; i < (INVEN_ARRAY_SIZE - 1); i++) {
  2349.         if ((inventory[i].flags2 & TR_ACTIVATE) && known2_p(&(inventory[i]))) {
  2350.             if (j == choice)
  2351.             break;
  2352.             j++;
  2353.         }
  2354.         }
  2355.  
  2356.         if ( (test && verify("Activate", i)) || !test)
  2357.         flag = TRUE;
  2358.         else {
  2359.         flag = TRUE;           /* exit loop, he didn't want to try it... */
  2360.         free_turn_flag = TRUE; /* but he didn't do anything either */
  2361.         continue;
  2362.         }
  2363.  
  2364.         if (inventory[i].timeout > 0) {
  2365.         msg_print("It whines, glows and fades...");
  2366.         break;
  2367.         }
  2368.         if (py.stats.use_stat[A_INT] < randint(18) &&
  2369.          randint(object_list[inventory[i].index].level) > py.misc.lev) {
  2370.         msg_print("You fail to activate it properly.");
  2371.         break;
  2372.         }
  2373.         msg_print("You activate it...");
  2374.         switch (inventory[i].index) {
  2375.           case (29):
  2376.           case (395):
  2377.           case (396):       /* The dreaded daggers:-> */
  2378.           case (397):
  2379.         if (inventory[i].name2 == SN_NARTHANC) {
  2380.             msg_print("Your dagger is covered in fire...");
  2381.             if (get_dir(NULL, &dir)) {
  2382.             if (py.flags.confused > 0) {
  2383.                 msg_print("You are confused.");
  2384.                 do {
  2385.                 dir = randint(9);
  2386.                 } while (dir == 5);
  2387.             }
  2388.             fire_bolt(GF_FIRE, dir, char_row, char_col, damroll(9, 8));
  2389.             inventory[i].timeout = 5 + randint(10);
  2390.             }
  2391.         } else if (inventory[i].name2 == SN_NIMTHANC) {
  2392.             msg_print("Your dagger is covered in frost...");
  2393.             if (get_dir(NULL, &dir)) {
  2394.             if (py.flags.confused > 0) {
  2395.                 msg_print("You are confused.");
  2396.                 do {
  2397.                 dir = randint(9);
  2398.                 } while (dir == 5);
  2399.             }
  2400.             fire_bolt(GF_FROST, dir, char_row, char_col, damroll(6, 8));
  2401.             inventory[i].timeout = 4 + randint(8);
  2402.             }
  2403.         } else if (inventory[i].name2 == SN_DETHANC) {
  2404.             msg_print("Your dagger is covered in sparks...");
  2405.             if (get_dir(NULL, &dir)) {
  2406.             if (py.flags.confused > 0) {
  2407.                 msg_print("You are confused.");
  2408.                 do {
  2409.                 dir = randint(9);
  2410.                 } while (dir == 5);
  2411.             }
  2412.             fire_bolt(GF_LIGHTNING, dir, char_row, char_col, damroll(4, 8));
  2413.             inventory[i].timeout = 3 + randint(7);
  2414.             }
  2415.         } else if (inventory[i].name2 == SN_RILIA) {
  2416.             msg_print("Your dagger throbs deep green...");
  2417.             if (get_dir(NULL, &dir)) {
  2418.             if (py.flags.confused > 0) {
  2419.                 msg_print("You are confused.");
  2420.                 do {
  2421.                 dir = randint(9);
  2422.                 } while (dir == 5);
  2423.             }
  2424.             fire_ball(GF_POISON_GAS, dir, char_row, char_col, 12, 3);
  2425.             inventory[i].timeout = 3 + randint(3);
  2426.             }
  2427.         } else if (inventory[i].name2 == SN_BELANGIL) {
  2428.             msg_print("Your dagger is covered in frost...");
  2429.             if (get_dir(NULL, &dir)) {
  2430.             if (py.flags.confused > 0) {
  2431.                 msg_print("You are confused.");
  2432.                 do {
  2433.                 dir = randint(9);
  2434.                 } while (dir == 5);
  2435.             }
  2436.             fire_ball(GF_FROST, dir, char_row, char_col, 48, 2);
  2437.             inventory[i].timeout = 3 + randint(7);
  2438.             }
  2439.         }
  2440.         break;
  2441.           case (91):
  2442.         if (inventory[i].name2 == SN_DAL) {
  2443.             msg_print("You feel energy flow through your feet...");
  2444.             remove_fear();
  2445.             cure_poison();
  2446.             inventory[i].timeout = 5;
  2447.         }
  2448.         break;
  2449.           case (42):
  2450.           case (43):
  2451.         if (inventory[i].name2 == SN_RINGIL) {
  2452.             msg_print("Your sword glows an intense blue...");
  2453.             if (get_dir(NULL, &dir)) {
  2454.             if (py.flags.confused > 0) {
  2455.                 msg_print("You are confused.");
  2456.                 do {
  2457.                 dir = randint(9);
  2458.                 } while (dir == 5);
  2459.             }
  2460.             fire_ball(GF_FROST, dir, char_row, char_col, 100, 2);
  2461.             inventory[i].timeout = 300;
  2462.             }
  2463.         } else if (inventory[i].name2 == SN_ANDURIL) {
  2464.             msg_print("Your sword glows an intense red...");
  2465.             if (get_dir(NULL, &dir)) {
  2466.             if (py.flags.confused > 0) {
  2467.                 msg_print("You are confused.");
  2468.                 do {
  2469.                 dir = randint(9);
  2470.                 } while (dir == 5);
  2471.             }
  2472.             fire_ball(GF_FIRE, dir, char_row, char_col, 72, 2);
  2473.             inventory[i].timeout = 400;
  2474.             }
  2475.         }
  2476.         break;
  2477.           case (52):
  2478.         if (inventory[i].name2 == SN_FIRESTAR) {
  2479.             msg_print("Your morningstar rages in fire...");
  2480.             if (get_dir(NULL, &dir)) {
  2481.             if (py.flags.confused > 0) {
  2482.                 msg_print("You are confused.");
  2483.                 do {
  2484.                 dir = randint(9);
  2485.                 } while (dir == 5);
  2486.             }
  2487.             fire_ball(GF_FIRE, dir, char_row, char_col, 72, 3);
  2488.             inventory[i].timeout = 100;
  2489.             }
  2490.         }
  2491.         break;
  2492.           case (92):
  2493.         if (inventory[i].name2 == SN_FEANOR) {
  2494.             py.flags.fast += randint(25) + 15;
  2495.             inventory[i].timeout = 200;
  2496.         }
  2497.         break;
  2498.           case (59):
  2499.         if (inventory[i].name2 == SN_THEODEN) {
  2500.             msg_print("The blade of your axe glows black...");
  2501.             if (get_dir(NULL, &dir)) {
  2502.             if (py.flags.confused > 0) {
  2503.                 msg_print("You are confused.");
  2504.                 do {
  2505.                 dir = randint(9);
  2506.                 } while (dir == 5);
  2507.             }
  2508.             drain_life(dir, char_row, char_col, 120);
  2509.             inventory[i].timeout = 400;
  2510.             }
  2511.         }
  2512.         break;
  2513.           case (62):
  2514.         if (inventory[i].name2 == SN_TURMIL) {
  2515.             msg_print("The head of your hammer glows white...");
  2516.             if (get_dir(NULL, &dir)) {
  2517.             if (py.flags.confused > 0) {
  2518.                 msg_print("You are confused.");
  2519.                 do {
  2520.                 dir = randint(9);
  2521.                 } while (dir == 5);
  2522.             }
  2523.             drain_life(dir, char_row, char_col, 90);
  2524.             inventory[i].timeout = 70;
  2525.             }
  2526.         }
  2527.         break;
  2528.           case (111):
  2529.         if (inventory[i].name2 == SN_CASPANION) {
  2530.             msg_print("Your mail magically disarms traps...");
  2531.             td_destroy();
  2532.             inventory[i].timeout = 10;
  2533.         }
  2534.         break;
  2535.           case (71):
  2536.         if (inventory[i].name2 == SN_AVAVIR) {
  2537.             if (py.flags.word_recall == 0) {
  2538.             py.flags.word_recall = 15 + randint(20);
  2539.             msg_print("The air about you becomes charged...");
  2540.             } else {
  2541.             py.flags.word_recall = 0;
  2542.             msg_print("A tension leaves the air around you...");
  2543.             }
  2544.             inventory[i].timeout = 200;
  2545.         }
  2546.         break;
  2547.           case (53):
  2548.         if (inventory[i].name2 == SN_TARATOL) {
  2549.             if (py.flags.fast == 0)
  2550.             py.flags.fast += randint(30) + 15;
  2551.             inventory[i].timeout = 166;
  2552.         }
  2553.         break;
  2554.           case (54):
  2555.         if (inventory[i].name2 == SN_ERIRIL) {
  2556.             ident_spell();
  2557.             inventory[i].timeout = 10;
  2558.         } else if (inventory[i].name2 == SN_OLORIN) {
  2559.             probing();
  2560.             inventory[i].timeout = 20;
  2561.         }
  2562.         break;
  2563.           case (67):
  2564.         if (inventory[i].name2 == SN_EONWE) {
  2565.             msg_print("Your axe lets out a long, shrill note...");
  2566.             mass_genocide(TRUE);
  2567.             inventory[i].timeout = 1000;
  2568.         }
  2569.         break;
  2570.           case (68):
  2571.         if (inventory[i].name2 == SN_LOTHARANG) {
  2572.             msg_print("Your battle axe radiates deep purple...");
  2573.             hp_player(damroll(4, 7));
  2574.             if (py.flags.cut > 0) {
  2575.             py.flags.cut = (py.flags.cut / 2) - 50;
  2576.             if (py.flags.cut < 0)
  2577.                 py.flags.cut = 0;
  2578.             msg_print("You wounds heal.");
  2579.             }
  2580.             inventory[i].timeout = 2 + randint(2);
  2581.         }
  2582.         break;
  2583.           case (75):
  2584.         if (inventory[i].name2 == SN_CUBRAGOL) {
  2585.             for (a = 0; a < INVEN_WIELD; a++)
  2586. /* search for bolts that are not cursed and are not already named -CWS */
  2587.             if ((inventory[a].tval == TV_BOLT) &&
  2588.                 !(inventory[a].flags & TR_CURSED) &&
  2589.                 (inventory[a].name2 == SN_NULL))
  2590.                 break;
  2591.             if (a < INVEN_WIELD) {
  2592.             i_ptr = &inventory[a];
  2593.             msg_print("Your bolts are covered in a fiery aura!");
  2594.             i_ptr->name2 = SN_FIRE;
  2595.             i_ptr->flags |= (TR_FLAME_TONGUE|TR_RES_FIRE);
  2596.             i_ptr->cost += 25;
  2597.             enchant(i_ptr, 3+randint(3), ENCH_TOHIT|ENCH_TODAM);
  2598.             calc_bonuses();
  2599.             } else {
  2600.             msg_print("The fiery enchantment fails.");
  2601.             }
  2602.             inventory[i].timeout = 999;
  2603.         }
  2604.         break;
  2605.           case (34):
  2606.           case (35):
  2607.         if (inventory[i].name2 == SN_ARUNRUTH) {
  2608.             msg_print("Your sword glows a pale blue...");
  2609.             if (get_dir(NULL, &dir)) {
  2610.             if (py.flags.confused > 0) {
  2611.                 msg_print("You are confused.");
  2612.                 do {
  2613.                 dir = randint(9);
  2614.                 } while (dir == 5);
  2615.             }
  2616.             fire_bolt(GF_FROST, dir, char_row, char_col, damroll(12, 8));
  2617.             inventory[i].timeout = 500;
  2618.             }
  2619.         }
  2620.         break;
  2621.           case (64):
  2622.         if (inventory[i].name2 == SN_AEGLOS) {
  2623.             msg_print("Your spear glows a bright white...");
  2624.             if (get_dir(NULL, &dir)) {
  2625.             if (py.flags.confused > 0) {
  2626.                 msg_print("You are confused.");
  2627.                 do {
  2628.                 dir = randint(9);
  2629.                 } while (dir == 5);
  2630.             }
  2631.             fire_ball(GF_FROST, dir, char_row, char_col, 100, 2);
  2632.             inventory[i].timeout = 500;
  2633.             }
  2634.         } else if (inventory[i].name2 == SN_OROME) {
  2635.             msg_print("Your spear pulsates...");
  2636.             if (get_dir(NULL, &dir)) {
  2637.             if (py.flags.confused > 0) {
  2638.                 msg_print("You are confused.");
  2639.                 do {
  2640.                 dir = randint(9);
  2641.                 } while (dir == 5);
  2642.             }
  2643.             wall_to_mud(dir, char_row, char_col);
  2644.             inventory[i].timeout = 5;
  2645.             }
  2646.         }
  2647.         break;
  2648.           case (118):
  2649.         if (inventory[i].name2 == SN_SOULKEEPER) {
  2650.             msg_print("Your armour glows a bright white...");
  2651.             msg_print("You feel much better...");
  2652.             hp_player(1000);
  2653.             inventory[i].timeout = 888;
  2654.         }
  2655.         break;
  2656.           case (120):
  2657.         if (inventory[i].name2 == SN_BELEGENNON) {
  2658.             teleport(10);
  2659.             inventory[i].timeout = 2;
  2660.         }
  2661.         break;
  2662.           case (119):
  2663.         if (inventory[i].name2 == SN_CELEBORN) {
  2664.             genocide(TRUE);
  2665.             inventory[i].timeout = 500;
  2666.         }
  2667.         break;
  2668.           case (124):
  2669.         if (inventory[i].name2 == SN_LUTHIEN) {
  2670.             restore_level();
  2671.             inventory[i].timeout = 450;
  2672.         }
  2673.         break;
  2674.           case (65):
  2675.         if (inventory[i].name2 == SN_ULMO) {
  2676.             msg_print("Your trident glows deep red...");
  2677.             if (get_dir(NULL, &dir)) {
  2678.             if (py.flags.confused > 0) {
  2679.                 msg_print("You are confused.");
  2680.                 do {
  2681.                 dir = randint(9);
  2682.                 } while (dir == 5);
  2683.             }
  2684.             teleport_monster(dir, char_row, char_col);
  2685.             inventory[i].timeout = 150;
  2686.             }
  2687.         }
  2688.         break;
  2689.           case (123):       /* Cloak */
  2690.           case (411):
  2691.         if (inventory[i].name2 == SN_COLLUIN) {
  2692.             msg_print("Your cloak glows many colours...");
  2693.             msg_print("You feel you can resist anything.");
  2694.             py.flags.resist_heat += randint(20) + 20;
  2695.             py.flags.resist_cold += randint(20) + 20;
  2696.             py.flags.resist_light += randint(20) + 20;
  2697.             py.flags.resist_poison += randint(20) + 20;
  2698.             py.flags.resist_acid += randint(20) + 20;
  2699.             inventory[i].timeout = 111;
  2700.         } else if (inventory[i].name2 == SN_HOLCOLLETH) {
  2701.             msg_print("You momentarily disappear...");
  2702.             sleep_monsters1(char_row, char_col);
  2703.             inventory[i].timeout = 55;
  2704.         } else if (inventory[i].name2 == SN_THINGOL) {
  2705.             msg_print("You hear a low humming noise...");
  2706.             recharge(60);
  2707.             inventory[i].timeout = 70;
  2708.         } else if (inventory[i].name2 == SN_COLANNON) {
  2709.             teleport(100);
  2710.             inventory[i].timeout = 45;
  2711.         }
  2712.         break;
  2713.           case (50):       /* Flail */
  2714.         if (inventory[i].name2 == SN_TOTILA) {
  2715.             msg_print("Your flail glows in scintillating colours...");
  2716.             if (get_dir(NULL, &dir)) {
  2717.             if (py.flags.confused > 0) {
  2718.                 msg_print("You are confused.");
  2719.                 do {
  2720.                 dir = randint(9);
  2721.                 } while (dir == 5);
  2722.             }
  2723.             confuse_monster(dir, char_row, char_col, 20);
  2724.             inventory[i].timeout = 15;
  2725.             }
  2726.         }
  2727.         break;
  2728.           case (125):       /* Gloves */
  2729.         if (inventory[i].name2 == SN_CAMMITHRIM) {
  2730.             msg_print("Your gloves glow extremely brightly...");
  2731.             if (get_dir(NULL, &dir)) {
  2732.             if (py.flags.confused > 0) {
  2733.                 msg_print("You are confused.");
  2734.                 do {
  2735.                 dir = randint(9);
  2736.                 } while (dir == 5);
  2737.             }
  2738.             fire_bolt(GF_MAGIC_MISSILE, dir, char_row, char_col,
  2739.                   damroll(2, 6));
  2740.             inventory[i].timeout = 2;
  2741.             }
  2742.         }
  2743.         break;
  2744.           case (126):       /* Gauntlets */
  2745.         if (inventory[i].name2 == SN_PAURHACH) {
  2746.             msg_print("Your gauntlets are covered in fire...");
  2747.             if (get_dir(NULL, &dir)) {
  2748.             if (py.flags.confused > 0) {
  2749.                 msg_print("You are confused.");
  2750.                 do {
  2751.                 dir = randint(9);
  2752.                 } while (dir == 5);
  2753.             }
  2754.             if (randint(4)==1)
  2755.                 line_spell(GF_FIRE, dir, char_row, char_col, damroll(9,8));
  2756.             else
  2757.                 fire_bolt(GF_FIRE, dir, char_row, char_col, damroll(9,8));
  2758.             inventory[i].timeout = 5 + randint(10);
  2759.             }
  2760.         } else if (inventory[i].name2 == SN_PAURNIMMEN) {
  2761.             msg_print("Your gauntlets are covered in frost...");
  2762.             if (get_dir(NULL, &dir)) {
  2763.             if (py.flags.confused > 0) {
  2764.                 msg_print("You are confused.");
  2765.                 do {
  2766.                 dir = randint(9);
  2767.                 } while (dir == 5);
  2768.             }
  2769.             fire_bolt(GF_FROST, dir, char_row, char_col, damroll(6, 8));
  2770.             inventory[i].timeout = 4 + randint(8);
  2771.             }
  2772.         } else if (inventory[i].name2 == SN_PAURAEGEN) {
  2773.             msg_print("Your gauntlets are covered in sparks...");
  2774.             if (get_dir(NULL, &dir)) {
  2775.             if (py.flags.confused > 0) {
  2776.                 msg_print("You are confused.");
  2777.                 do {
  2778.                 dir = randint(9);
  2779.                 } while (dir == 5);
  2780.             }
  2781.             fire_bolt(GF_LIGHTNING, dir, char_row, char_col, damroll(4, 8));
  2782.             inventory[i].timeout = 3 + randint(7);
  2783.             }
  2784.         } else if (inventory[i].name2 == SN_PAURNEN) {
  2785.             msg_print("Your gauntlets look very acidic...");
  2786.             if (get_dir(NULL, &dir)) {
  2787.             if (py.flags.confused > 0) {
  2788.                 msg_print("You are confused.");
  2789.                 do {
  2790.                 dir = randint(9);
  2791.                 } while (dir == 5);
  2792.             }
  2793.             fire_bolt(GF_ACID, dir, char_row, char_col, damroll(5, 8));
  2794.             inventory[i].timeout = 4 + randint(7);
  2795.             }
  2796.         }
  2797.         break;
  2798.           case (127):
  2799.         if (inventory[i].name2 == SN_FINGOLFIN) {
  2800.             msg_print("Magical spikes appear on your cesti...");
  2801.             if (get_dir(NULL, &dir)) {
  2802.             if (py.flags.confused > 0) {
  2803.                 msg_print("You are confused.");
  2804.                 do {
  2805.                 dir = randint(9);
  2806.                 } while (dir == 5);
  2807.             }
  2808.             fire_bolt(GF_ARROW, dir, char_row, char_col, 150);
  2809.             inventory[i].timeout = 88 + randint(88);
  2810.             }
  2811.         }
  2812.         break;
  2813.           case (96):
  2814.         if (inventory[i].name2 == SN_HOLHENNETH) {
  2815.             msg_print("You close your eyes and an image forms in your mind...");
  2816.             detection();
  2817.             inventory[i].timeout = 55 + randint(55);
  2818.         }
  2819.         break;
  2820.           case (99):
  2821.         if (inventory[i].name2 == SN_GONDOR) {
  2822.             msg_print("You feel a warm tingling inside...");
  2823.             hp_player(500);
  2824.             inventory[i].timeout = 500;
  2825.         }
  2826.         break;
  2827.           case (SPECIAL_OBJ - 1):    /* Narya */
  2828.         msg_print("The ring glows deep red...");
  2829.         if (get_dir(NULL, &dir)) {
  2830.             if (py.flags.confused > 0) {
  2831.             msg_print("You are confused.");
  2832.             do {
  2833.                 dir = randint(9);
  2834.             } while (dir == 5);
  2835.             }
  2836.             fire_ball(GF_FIRE, dir, char_row, char_col, 120, 3);
  2837.             inventory[i].timeout = 222 + randint(222);
  2838.         }
  2839.         break;
  2840.           case (SPECIAL_OBJ): /* Nenya */
  2841.         msg_print("The ring glows bright white...");
  2842.         if (get_dir(NULL, &dir)) {
  2843.             if (py.flags.confused > 0) {
  2844.             msg_print("You are confused.");
  2845.             do {
  2846.                 dir = randint(9);
  2847.             } while (dir == 5);
  2848.             }
  2849.             fire_ball(GF_FROST, dir, char_row, char_col, 200, 3);
  2850.             inventory[i].timeout = 222 + randint(333);
  2851.         }
  2852.         break;
  2853.           case (SPECIAL_OBJ + 1):    /* Vilya */
  2854.         msg_print("The ring glows deep blue...");
  2855.         if (get_dir(NULL, &dir)) {
  2856.             if (py.flags.confused > 0) {
  2857.             msg_print("You are confused.");
  2858.             do {
  2859.                 dir = randint(9);
  2860.             } while (dir == 5);
  2861.             }
  2862.             fire_ball(GF_LIGHTNING, dir, char_row, char_col, 250, 3);
  2863.             inventory[i].timeout = 222 + randint(444);
  2864.         }
  2865.         break;
  2866.           case (SPECIAL_OBJ + 2):    /* Power */
  2867.         msg_print("The ring glows intensely black...");
  2868.         switch (randint(17) + (8 - py.misc.lev / 10)) {
  2869.           case 5:
  2870.             dispel_creature(0xFFFFFFFL, 1000);
  2871.             break;
  2872.           case 6:
  2873.           case 7:
  2874.             msg_print("You are surrounded by a malignant aura");
  2875.             m_ptr = &py.misc;
  2876.             m_ptr->lev--;
  2877.             m_ptr->exp = player_exp[m_ptr->lev - 2] * m_ptr->expfact / 100 +
  2878.             randint((player_exp[m_ptr->lev - 1] * m_ptr->expfact / 100) -
  2879.                (player_exp[m_ptr->lev - 2] * m_ptr->expfact / 100));
  2880.             m_ptr->max_exp = m_ptr->exp;
  2881.             prt_experience();
  2882.             ruin_stat(A_STR);
  2883.             ruin_stat(A_INT);
  2884.             ruin_stat(A_WIS);
  2885.             ruin_stat(A_DEX);
  2886.             ruin_stat(A_CON);
  2887.             ruin_stat(A_CHR);
  2888.             calc_hitpoints();
  2889.             if (class[m_ptr->pclass].spell == MAGE) {
  2890.             calc_spells(A_INT);
  2891.             calc_mana(A_INT);
  2892.             } else if (class[m_ptr->pclass].spell == PRIEST) {
  2893.             calc_spells(A_WIS);
  2894.             calc_mana(A_WIS);
  2895.             }
  2896.             prt_level();
  2897.             prt_title();
  2898.             take_hit((py.misc.chp > 2) ? py.misc.chp / 2 : 0, "malignant aura");
  2899.             break;
  2900.           case 8:
  2901.           case 9:
  2902.           case 10:
  2903.             if (get_dir(NULL, &dir)) {
  2904.             if (py.flags.confused > 0) {
  2905.                 msg_print("You are confused.");
  2906.                 do {
  2907.                 dir = randint(9);
  2908.                 } while (dir == 5);
  2909.             }
  2910.             fire_ball(GF_MANA, dir, char_row, char_col, 300, 3);
  2911.             }
  2912.             break;
  2913.           default:
  2914.             if (get_dir(NULL, &dir)) {
  2915.             if (py.flags.confused > 0) {
  2916.                 msg_print("You are confused.");
  2917.                 do {
  2918.                 dir = randint(9);
  2919.                 } while (dir == 5);
  2920.             }
  2921.             fire_bolt(GF_MANA, dir, char_row, char_col, 250);
  2922.             }
  2923.         }
  2924.         inventory[i].timeout = 444 + randint(444);
  2925.         break;
  2926.           case (389):       /* Blue */
  2927.         msg_print("You breathe lightning...");
  2928.         if (get_dir(NULL, &dir)) {
  2929.             if (py.flags.confused > 0) {
  2930.             msg_print("You are confused.");
  2931.             do {
  2932.                 dir = randint(9);
  2933.             } while (dir == 5);
  2934.             }
  2935.             fire_ball(GF_LIGHTNING, dir, char_row, char_col, 100, 2);
  2936.             inventory[i].timeout = 444 + randint(444);
  2937.         }
  2938.         break;
  2939.           case (390):       /* White */
  2940.         msg_print("You breathe frost...");
  2941.         if (get_dir(NULL, &dir)) {
  2942.             if (py.flags.confused > 0) {
  2943.             msg_print("You are confused.");
  2944.             do {
  2945.                 dir = randint(9);
  2946.             } while (dir == 5);
  2947.             }
  2948.             fire_ball(GF_FROST, dir, char_row, char_col, 110, 2);
  2949.             inventory[i].timeout = 444 + randint(444);
  2950.         }
  2951.         break;
  2952.           case (391):       /* Black */
  2953.         msg_print("You breathe acid...");
  2954.         if (get_dir(NULL, &dir)) {
  2955.             if (py.flags.confused > 0) {
  2956.             msg_print("You are confused.");
  2957.             do {
  2958.                 dir = randint(9);
  2959.             } while (dir == 5);
  2960.             }
  2961.             fire_ball(GF_ACID, dir, char_row, char_col, 130, 2);
  2962.             inventory[i].timeout = 444 + randint(444);
  2963.         }
  2964.         break;
  2965.           case (392):       /* Gas */
  2966.         msg_print("You breathe poison gas...");
  2967.         if (get_dir(NULL, &dir)) {
  2968.             if (py.flags.confused > 0) {
  2969.             msg_print("You are confused.");
  2970.             do {
  2971.                 dir = randint(9);
  2972.             } while (dir == 5);
  2973.             }
  2974.             fire_ball(GF_POISON_GAS, dir, char_row, char_col, 150, 2);
  2975.             inventory[i].timeout = 444 + randint(444);
  2976.         }
  2977.         break;
  2978.           case (393):       /* Fire */
  2979.         msg_print("You breathe fire...");
  2980.         if (get_dir(NULL, &dir)) {
  2981.             if (py.flags.confused > 0) {
  2982.             msg_print("You are confused.");
  2983.             do {
  2984.                 dir = randint(9);
  2985.             } while (dir == 5);
  2986.             }
  2987.             fire_ball(GF_FIRE, dir, char_row, char_col, 200, 2);
  2988.             inventory[i].timeout = 444 + randint(444);
  2989.         }
  2990.         break;
  2991.           case (394):       /* Multi-hued */
  2992.         if (inventory[i].name2 == SN_RAZORBACK) {
  2993.             msg_print("A storm of lightning spikes fires in all directions...");
  2994.             starball(char_row, char_col);
  2995.             inventory[i].timeout = 1000;
  2996.         } else {
  2997.             if (get_dir(NULL, &dir)) {
  2998.             if (py.flags.confused > 0) {
  2999.                 msg_print("You are confused.");
  3000.                 do {
  3001.                 dir = randint(9);
  3002.                 } while (dir == 5);
  3003.             }
  3004.             choice = randint(5);
  3005.             sprintf(tmp2, "You breathe %s...",
  3006.                 ((choice == 1) ? "lightning" :
  3007.                  ((choice == 2) ? "frost" :
  3008.                   ((choice == 3) ? "acid" :
  3009.                 ((choice == 4) ? "poison gas" : "fire")))));
  3010.             msg_print(tmp2);
  3011.             fire_ball(((choice == 1) ? GF_LIGHTNING :
  3012.                    ((choice == 2) ? GF_FROST :
  3013.                     ((choice == 3) ? GF_ACID :
  3014.                    ((choice == 4) ? GF_POISON_GAS : GF_FIRE)))),
  3015.                   dir, char_row, char_col, 250, 2);
  3016.             inventory[i].timeout = 222 + randint(222);
  3017.             }
  3018.         }
  3019.         break;
  3020.           case (408):       /* Bronze */
  3021.         msg_print("You breathe confusion...");
  3022.         if (get_dir(NULL, &dir)) {
  3023.             if (py.flags.confused > 0) {
  3024.             msg_print("You are confused.");
  3025.             do {
  3026.                 dir = randint(9);
  3027.             } while (dir == 5);
  3028.             }
  3029.             fire_ball(GF_CONFUSION, dir, char_row, char_col, 120, 2);
  3030.             inventory[i].timeout = 444 + randint(444);
  3031.         }
  3032.         break;
  3033.           case (409):       /* Gold */
  3034.         msg_print("You breathe sound...");
  3035.         if (get_dir(NULL, &dir)) {
  3036.             if (py.flags.confused > 0) {
  3037.             msg_print("You are confused.");
  3038.             do {
  3039.                 dir = randint(9);
  3040.             } while (dir == 5);
  3041.             }
  3042.             fire_ball(GF_SOUND, dir, char_row, char_col, 130, 2);
  3043.             inventory[i].timeout = 444 + randint(444);
  3044.         }
  3045.         break;
  3046.           case (415):       /* Chaos */
  3047.         if (get_dir(NULL, &dir)) {
  3048.             if (py.flags.confused > 0) {
  3049.             msg_print("You are confused.");
  3050.             do {
  3051.                 dir = randint(9);
  3052.             } while (dir == 5);
  3053.             }
  3054.             choice = randint(2);
  3055.             sprintf(tmp2, "You breathe %s...",
  3056.                 ((choice == 1 ? "chaos" : "disenchantment")));
  3057.             msg_print(tmp2);
  3058.             fire_ball((choice == 1 ? GF_CHAOS : GF_DISENCHANT), dir,
  3059.                   char_row, char_col, 220, 2);
  3060.             inventory[i].timeout = 300 + randint(300);
  3061.         }
  3062.         break;
  3063.           case (416):       /* Law */
  3064.         if (get_dir(NULL, &dir)) {
  3065.             if (py.flags.confused > 0) {
  3066.             msg_print("You are confused.");
  3067.             do {
  3068.                 dir = randint(9);
  3069.             } while (dir == 5);
  3070.             }
  3071.             choice = randint(2);
  3072.             sprintf(tmp2, "You breathe %s...",
  3073.                 ((choice == 1 ? "sound" : "shards")));
  3074.             msg_print(tmp2);
  3075.             fire_ball((choice == 1 ? GF_SOUND : GF_SHARDS), dir,
  3076.                   char_row, char_col, 230, 2);
  3077.             inventory[i].timeout = 300 + randint(300);
  3078.         }
  3079.         break;
  3080.           case (417):       /* Balance */
  3081.         if (get_dir(NULL, &dir)) {
  3082.             if (py.flags.confused > 0) {
  3083.             msg_print("You are confused.");
  3084.             do {
  3085.                 dir = randint(9);
  3086.             } while (dir == 5);
  3087.             }
  3088.             choice = randint(4);
  3089.             sprintf(tmp2, "You breathe %s...",
  3090.                 ((choice == 1) ? "chaos" :
  3091.                  ((choice == 2) ? "disenchantment" :
  3092.                   ((choice == 3) ? "sound" : "shards"))));
  3093.             msg_print(tmp2);
  3094.             fire_ball(((choice == 1) ? GF_CHAOS :
  3095.                    ((choice == 2) ? GF_DISENCHANT :
  3096.                 ((choice == 3) ? GF_SOUND : GF_SHARDS))),
  3097.                   dir, char_row, char_col, 250, 2);
  3098.             inventory[i].timeout = 300 + randint(300);
  3099.         }
  3100.         break;
  3101.           case (418):       /* Shining */
  3102.         if (get_dir(NULL, &dir)) {
  3103.             if (py.flags.confused > 0) {
  3104.             msg_print("You are confused.");
  3105.             do {
  3106.                 dir = randint(9);
  3107.             } while (dir == 5);
  3108.             }
  3109.             choice = randint(2);
  3110.             sprintf(tmp2, "You breathe %s...",
  3111.                 ((choice == 1 ? "light" : "darkness")));
  3112.             msg_print(tmp2);
  3113.             fire_ball((choice == 1 ? GF_LIGHT : GF_DARK), dir,
  3114.                   char_row, char_col, 200, 2);
  3115.             inventory[i].timeout = 300 + randint(300);
  3116.         }
  3117.         break;
  3118.           case (419):       /* Power Dragon Scale Mail */
  3119.         if (inventory[i].name2 == SN_BLADETURNER) {
  3120.             msg_print("Your armour glows many colours...");
  3121.             msg_print("You enter a berserk rage...");
  3122.             py.flags.hero += randint(50) + 50;
  3123.             py.flags.shero += randint(50) + 50;
  3124.             bless(randint(50) + 50);
  3125.             py.flags.resist_heat += randint(50) + 50;
  3126.             py.flags.resist_cold += randint(50) + 50;
  3127.             py.flags.resist_light += randint(50) + 50;
  3128.             py.flags.resist_acid += randint(50) + 50;
  3129.             inventory[i].timeout = 400;
  3130.         } else {
  3131.             msg_print("You breathe the elements...");
  3132.             if (get_dir(NULL, &dir)) {
  3133.             if (py.flags.confused > 0) {
  3134.                 msg_print("You are confused.");
  3135.                 do {
  3136.                 dir = randint(9);
  3137.                 } while (dir == 5);
  3138.             }
  3139.             fire_ball(GF_MAGIC_MISSILE, dir, char_row, char_col, 300, 2);
  3140.             inventory[i].timeout = 300 + randint(300);
  3141.             }
  3142.         }
  3143.         break;
  3144.           case (SPECIAL_OBJ + 3):
  3145.         msg_print("The phial wells with clear light...");
  3146.         light_area(char_row, char_col, damroll(2, 15), 3);
  3147.         inventory[i].timeout = 10 + randint(10);
  3148.         break;
  3149.           case (SPECIAL_OBJ + 4):
  3150.         msg_print("An aura of good floods the area...");
  3151.         dispel_creature(EVIL, (int)(5 * py.misc.lev));
  3152.         inventory[i].timeout = 444 + randint(222);
  3153.         break;
  3154.           case (SPECIAL_OBJ + 5):
  3155.         msg_print("The amulet lets out a shrill wail...");
  3156.         msg_print("You feel somewhat safer...");
  3157.         protect_evil();
  3158.         inventory[i].timeout = 222 + randint(222);
  3159.         break;
  3160.           case (SPECIAL_OBJ + 6):
  3161.         msg_print("The star shines brightly...");
  3162.         msg_print("And you sense your surroundings...");
  3163.         map_area();
  3164.         inventory[i].timeout = 50 + randint(50);
  3165.         break;
  3166.           case (SPECIAL_OBJ + 7):
  3167.         msg_print("The stone glows a deep green");
  3168.         wizard_light(TRUE);
  3169.         (void)detect_sdoor();
  3170.         (void)detect_trap();
  3171.         inventory[i].timeout = 100 + randint(100);
  3172.         break;
  3173.           case (SPECIAL_OBJ + 8):
  3174.         msg_print("The ring glows brightly...");
  3175.         py.flags.fast += randint(100) + 50;
  3176.         inventory[i].timeout = 200;
  3177.         break;
  3178.           default:
  3179.         (void)sprintf(tmp2, "Inventory num %d, index %d", i,
  3180.                   inventory[i].index);
  3181.         msg_print(tmp2);
  3182.         }
  3183.     }
  3184.     }
  3185.  
  3186.     if (redraw) {
  3187.     restore_screen();
  3188.     redraw = FALSE;
  3189.     }
  3190.     if (!flag)               /* if flag still false, then user aborted. 
  3191.                     * So we don't charge him a turn. -CFT */
  3192.     free_turn_flag = TRUE;
  3193. }
  3194.  
  3195. /* Examine a Book                    -RAK-     */
  3196. static void 
  3197. examine_book()
  3198. {
  3199.     int32u               j1;
  3200.     int32u               j2;
  3201.     int                  i, k, item_val, flag;
  3202.     int                  spell_index[63];
  3203.     register inven_type *i_ptr;
  3204.     register spell_type *s_ptr;
  3205.     int                  first_spell;
  3206.  
  3207.     if (!find_range(TV_MAGIC_BOOK, TV_PRAYER_BOOK, &i, &k))
  3208.     msg_print("You are not carrying any books.");
  3209.     else if (py.flags.blind > 0)
  3210.     msg_print("You can't see to read your spell book!");
  3211.     else if (no_light())
  3212.     msg_print("You have no light to read by.");
  3213.     else if (py.flags.confused > 0)
  3214.     msg_print("You are too confused.");
  3215.     else if (get_item(&item_val, "Which Book?", i, k, 0)) {
  3216.     flag = TRUE;
  3217.     i_ptr = &inventory[item_val];
  3218.     if (class[py.misc.pclass].spell == MAGE) {
  3219.         if (i_ptr->tval != TV_MAGIC_BOOK)
  3220.         flag = FALSE;
  3221.     } else if (class[py.misc.pclass].spell == PRIEST) {
  3222.         if (i_ptr->tval != TV_PRAYER_BOOK)
  3223.         flag = FALSE;
  3224.     } else
  3225.         flag = FALSE;
  3226.  
  3227.     if (!flag)
  3228.         msg_print("You do not understand the language.");
  3229.     else {
  3230.         i = 0;
  3231.         j1 = (int32u) inventory[item_val].flags;
  3232.         first_spell = bit_pos(&j1);    /* check which spell was first */
  3233.         j1 = (int32u) inventory[item_val].flags;    /* restore j1 value */
  3234.         while (j1) {
  3235.         k = bit_pos(&j1);
  3236.         s_ptr = &magic_spell[py.misc.pclass - 1][k];
  3237.         if (s_ptr->slevel < 99) {
  3238.             spell_index[i] = k;
  3239.             i++;
  3240.         }
  3241.         }
  3242.         j2 = (int32u) inventory[item_val].flags2;
  3243.         if (first_spell == -1) {    /* if none from other set of flags */
  3244.         first_spell = 32 + bit_pos(&j2);    /* get 1st spell # */
  3245.         j2 = (int32u) inventory[item_val].flags2;    /* and restore j2 */
  3246.         }
  3247.         while (j2) {
  3248.         k = bit_pos(&j2);
  3249.         s_ptr = &magic_spell[py.misc.pclass - 1][k + 32];
  3250.         if (s_ptr->slevel < 99) {
  3251.             spell_index[i] = (k + 32);
  3252.             i++;
  3253.         }
  3254.         }
  3255.         save_screen();
  3256.         print_spells(spell_index, i, TRUE, first_spell);
  3257.         pause_line(0);
  3258.         restore_screen();
  3259.     }
  3260.     }
  3261. }
  3262.  
  3263. /* Go up one level                    -RAK-     */
  3264. static void 
  3265. go_up()
  3266. {
  3267.     register cave_type *c_ptr;
  3268.     register int        no_stairs = FALSE;
  3269.  
  3270.     c_ptr = &cave[char_row][char_col];
  3271.     if (c_ptr->tptr != 0)
  3272.     if (t_list[c_ptr->tptr].tval == TV_UP_STAIR) {
  3273.         if (dun_level == Q_PLANE) {
  3274.         dun_level = 0;
  3275.         new_level_flag = TRUE;
  3276.         msg_print("You enter an inter-dimensional staircase. ");
  3277.         } else {
  3278.         dun_level--;
  3279.         new_level_flag = TRUE;
  3280.         if (dun_level > 0)
  3281.             create_down_stair = TRUE;
  3282.         msg_print("You enter a maze of up staircases. ");
  3283.         }
  3284.     } else
  3285.         no_stairs = TRUE;
  3286.     else
  3287.     no_stairs = TRUE;
  3288.  
  3289.     if (no_stairs) {
  3290.     msg_print("I see no up staircase here.");
  3291.     free_turn_flag = TRUE;
  3292.     }
  3293. }
  3294.  
  3295.  
  3296. /* Go down one level                    -RAK-     */
  3297. static void 
  3298. go_down()
  3299. {
  3300.     register cave_type *c_ptr;
  3301.     register int        no_stairs = FALSE;
  3302.  
  3303.     c_ptr = &cave[char_row][char_col];
  3304.     if (c_ptr->tptr != 0)
  3305.     if (t_list[c_ptr->tptr].tval == TV_DOWN_STAIR) {
  3306.         if (dun_level == Q_PLANE) {
  3307.         dun_level = 0;
  3308.         new_level_flag = TRUE;
  3309.         msg_print("You enter an inter-dimensional staircase. ");
  3310.         } else {
  3311.         dun_level++;
  3312.         new_level_flag = TRUE;
  3313.         create_up_stair = TRUE;
  3314.         msg_print("You enter a maze of down staircases. ");
  3315.         }
  3316.     } else
  3317.         no_stairs = TRUE;
  3318.     else
  3319.     no_stairs = TRUE;
  3320.  
  3321.     if (no_stairs) {
  3322.     msg_print("I see no down staircase here.");
  3323.     free_turn_flag = TRUE;
  3324.     }
  3325. }
  3326.  
  3327.  
  3328. /* Jam a closed door                    -RAK-     */
  3329. static void 
  3330. jamdoor()
  3331. {
  3332.     int                  y, x, dir, i, j;
  3333.     register cave_type  *c_ptr;
  3334.     register inven_type *t_ptr, *i_ptr;
  3335.     char                 tmp_str[80];
  3336. #ifdef TARGET
  3337.     int temp = target_mode; /* targetting will screw up get_dir.. -CFT */
  3338. #endif /* TARGET */
  3339.  
  3340.     free_turn_flag = TRUE;
  3341.     y = char_row;
  3342.     x = char_col;
  3343. #ifdef TARGET
  3344.     target_mode = FALSE; /* turn off target mode, restore later */
  3345. #endif
  3346.     if (get_dir(NULL, &dir)) {
  3347.     (void)mmove(dir, &y, &x);
  3348.     c_ptr = &cave[y][x];
  3349.     if (c_ptr->tptr != 0) {
  3350.         t_ptr = &t_list[c_ptr->tptr];
  3351.         if (t_ptr->tval == TV_CLOSED_DOOR)
  3352.         if (c_ptr->cptr == 0) {
  3353.             if (find_range(TV_SPIKE, TV_NEVER, &i, &j)) {
  3354.             free_turn_flag = FALSE;
  3355.             count_msg_print("You jam the door with a spike.");
  3356.             if (t_ptr->p1 > 0)
  3357.                 t_ptr->p1 = (-t_ptr->p1);    /* Make locked to stuck. */
  3358.             /* Successive spikes have a progressively smaller effect.
  3359.              * Series is: 0 20 30 37 43 48 52 56 60 64 67 70 ... 
  3360.              */
  3361.             t_ptr->p1 -= 1 + 190 / (10 - t_ptr->p1);
  3362.             i_ptr = &inventory[i];
  3363.             if (i_ptr->number > 1) {
  3364.                 i_ptr->number--;
  3365.                 inven_weight -= i_ptr->weight;
  3366.             } else
  3367.                 inven_destroy(i);
  3368.             } else
  3369.             msg_print("But you have no spikes.");
  3370.         } else {
  3371.             free_turn_flag = FALSE;
  3372.             (void)sprintf(tmp_str, "The %s is in your way!",
  3373.                   c_list[m_list[c_ptr->cptr].mptr].name);
  3374.             msg_print(tmp_str);
  3375.         }
  3376.         else if (t_ptr->tval == TV_OPEN_DOOR)
  3377.         msg_print("The door must be closed first.");
  3378.         else
  3379.         msg_print("That isn't a door!");
  3380.     } else
  3381.         msg_print("That isn't a door!");
  3382. #ifdef TARGET
  3383.     target_mode = temp;
  3384. #endif
  3385.     }
  3386. }
  3387.  
  3388.  
  3389. /* Refill the players lamp                -RAK-     */
  3390. static void 
  3391. refill_lamp()
  3392. {
  3393.     int                  i, j;
  3394.     register int         k;
  3395.     register inven_type *i_ptr;
  3396.  
  3397.     free_turn_flag = TRUE;
  3398.     k = inventory[INVEN_LIGHT].subval;
  3399.     if (k != 0)
  3400.     msg_print("But you are not using a lamp.");
  3401.     else if (!find_range(TV_FLASK, TV_NEVER, &i, &j))
  3402.     msg_print("You have no oil.");
  3403.     else {
  3404.     free_turn_flag = FALSE;
  3405.     i_ptr = &inventory[INVEN_LIGHT];
  3406.     i_ptr->p1 += inventory[i].p1;
  3407.     if (i_ptr->p1 > OBJ_LAMP_MAX) {
  3408.         i_ptr->p1 = OBJ_LAMP_MAX;
  3409.         msg_print("Your lamp overflows, spilling oil on the ground.");
  3410.         msg_print("Your lamp is full.");
  3411.     } else if (i_ptr->p1 > OBJ_LAMP_MAX / 2)
  3412.         msg_print("Your lamp is more than half full.");
  3413.     else if (i_ptr->p1 == OBJ_LAMP_MAX / 2)
  3414.         msg_print("Your lamp is half full.");
  3415.     else
  3416.         msg_print("Your lamp is less than half full.");
  3417.     desc_remain(i);
  3418.     inven_destroy(i);
  3419.     }
  3420. }
  3421.  
  3422. int 
  3423. is_quest(level)
  3424. int level;
  3425. {
  3426.     if (level == Q_PLANE)
  3427.     return FALSE;
  3428.     if (quests[SAURON_QUEST] && (level == quests[SAURON_QUEST]))
  3429.     return TRUE;
  3430.     return FALSE;
  3431. }
  3432.  
  3433. static void 
  3434. regen_monsters()
  3435. {
  3436.     register int i;
  3437.     int          frac;
  3438.  
  3439.     for (i = 0; i < MAX_MALLOC; i++) {
  3440.     if (m_list[i].hp >= 0) {
  3441.         if (m_list[i].maxhp == 0) {    /* then we're just going to fix it!
  3442.                      * -CFT */
  3443.         if ((c_list[m_list[i].mptr].cdefense & MAX_HP) || be_nasty)
  3444.             m_list[i].maxhp = max_hp(c_list[m_list[i].mptr].hd);
  3445.         else
  3446.             m_list[i].maxhp = pdamroll(c_list[m_list[i].mptr].hd);
  3447.         }
  3448.         if (m_list[i].hp < m_list[i].maxhp)
  3449.         m_list[i].hp += ((frac = 2 * m_list[i].maxhp / 100) > 0) ? frac : 1;
  3450.         if (m_list[i].hp > m_list[i].maxhp)
  3451.         m_list[i].hp = m_list[i].maxhp;
  3452.     } /* if hp >= 0 */
  3453.     } /* for loop */
  3454. }
  3455.  
  3456.  
  3457. static void
  3458. print_feeling()
  3459. {
  3460.     if (dun_level == 0)        /* snicker.... -CWS */
  3461.     msg_print("You feel there is something special about the town level.");
  3462.     else if (unfelt)
  3463.     msg_print("Looks like any other level.");
  3464.     else
  3465.     switch(feeling) {
  3466.       case 0:
  3467.         msg_print("Looks like any other level.");
  3468.         break;
  3469.       case 1:
  3470.         msg_print("You feel there is something special about this level.");
  3471.         break;
  3472.       case 2:
  3473.         msg_print("You have a superb feeling about this level.");
  3474.         break;
  3475.       case 3:
  3476.         msg_print("You have an excellent feeling that your luck is turning...");
  3477.         break;
  3478.       case 4:
  3479.         msg_print("You have a very good feeling.");
  3480.         break;
  3481.       case 5:
  3482.         msg_print("You have a good feeling.");
  3483.         break;
  3484.       case 6:
  3485.         msg_print("You feel strangely lucky.");
  3486.         break;
  3487.       case 7:
  3488.         msg_print("You feel your luck is turning...");
  3489.         break;
  3490.       case 8:
  3491.         msg_print("You like the look of this place.");
  3492.         break;
  3493.       case 9:
  3494.         msg_print("This level can't be all bad...");
  3495.         break;
  3496.       default:
  3497.         msg_print("What a boring place...");
  3498.         break;
  3499.     }
  3500. }
  3501.